Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack ICacheClient Increment not working

I have a problem with ServiceStack.CacheAccess.Memcached.MemcachedClientCache. The Increment method does not work as expected.

For the test, I am using a regular console app and the ICacheClient interface.

According to the method documentation :

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.

So here we go:

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

The result :

  • test removed: True
  • added True
  • first increment : 0
  • first read: 1
  • second increment: 0
  • second read: 1

As you can see, increment does not works.

The config for 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>

Did I missed something ?

like image 976
Pascal Amey Avatar asked Nov 04 '22 12:11

Pascal Amey


1 Answers

You can not read the value of a counter in this manner, there is an explanation of why in one of the closed issues of the Enyim project (here). Instead just increment the counter by 0.

var v = cacheClient.Increment(key, 0);
like image 85
David Avatar answered Nov 15 '22 16:11

David