Pas*_*mey 5 memcached servicestack
我有ServiceStack.CacheAccess.Memcached的问题.MemcachedClientCache.该Increment方法无法按预期工作.
对于测试,我使用的是常规控制台应用程序和ICacheClient界面.
根据方法文档:
必须先将项目插入缓存,然后才能更改该项目.
该项必须作为a插入System.String.
该操作仅适用于System.UInt32values,因此-1始终表示未找到该项.
所以我们走了:
ICacheClient client = new MemcachedClientCache();
string key = "test";
bool result = client.Remove(key);
Console.WriteLine("{0} removed: {1}", key, result);
//The item must be inserted as a System.String.
result = client.Add(key, "1");
Console.WriteLine("added {0}", result);
long v = client.Increment(key, 1);
Console.WriteLine("first increment : {0}", v);
string o = client.Get<string>(key);
Console.WriteLine("first read: {0}", o);
v = client.Increment(key, 1);
Console.WriteLine("second increment: {0}", v);
o = client.Get<string>(key);
Console.WriteLine("second read: {0}", o);
Run Code Online (Sandbox Code Playgroud)
结果 :
如您所见,增量不起作用.
enyim的配置:
<enyim.com>
<memcached protocol="Binary">
<servers>
<!-- make sure you use the same ordering of nodes in every configuration you have -->
<add address="memcached-dev1"
port="11211" />
</servers>
<socketPool minPoolSize="10"
maxPoolSize="100"
connectionTimeout="00:00:10"
deadTimeout="00:02:00" />
</memcached>
</enyim.com>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
您无法以这种方式读取计数器的值,在 Enyim 项目的一个已关闭问题(此处)中对此有解释。相反,只需将计数器增加 0。
var v = cacheClient.Increment(key, 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
536 次 |
| 最近记录: |