gpt4 book ai didi

memcached - ServiceStack ICacheClient 增量不起作用

转载 作者:行者123 更新时间:2023-12-02 11:28:05 25 4
gpt4 key购买 nike

我的 ServiceStack.CacheAccess.Memcached 有问题。MemcachedClientCacheIncrement 方法未按预期工作。

对于测试,我使用常规控制台应用程序和 ICacheClient 界面。

根据方法文档:

The item must be inserted into the cache before it can be changed.
The item must be inserted as a System.String.
The operation only works with System.UInt32values, so -1 always indicates that the item was not found.

所以我们开始:

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);

结果:

  • 测试已删除:True
  • 添加了 True
  • 第一个增量:0
  • 首次阅读:1
  • 第二个增量:0
  • 第二次阅读:1

如您所见,增量不起作用。

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>

我错过了什么吗?

最佳答案

您无法以这种方式读取计数器的值,在 Enyim 项目的一个已关闭问题 ( here ) 中对此有解释。相反,只需将计数器增加 0。

var v = cacheClient.Increment(key, 0);

关于memcached - ServiceStack ICacheClient 增量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13142056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com