Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Increment/Decrement not working as expected #86

Closed
lordfist opened this Issue Oct 29, 2011 · 8 comments

Comments

Projects
None yet
3 participants

Here is the problem:

Lets imagine 2 scenarios, in one I start with:

ulong val = Global.ClientPool.Client.Increment("testInt", 0, 1);

and call this ++ times afterwards. Now this works as expected and returns me correct values.

BUT

If I call this first:

Global.ClientPool.Client.Store(Enyim.Caching.Memcached.StoreMode.Set, "testInt", (ulong)0);

and then call

ulong val = Global.ClientPool.Client.Increment("testInt", 0, 1);

++ times it ALWAYS returns 0 as value.

This is clearly a bug and needs fixing asap or very big red letters that you cannot combine Store method with Increment/Decrement methods!!!

This also means that I cannot "RESET" the counter to 0 but need to Remove and then use Increment again...

Also note ANY CALLING on Store method afterwards does the same...

Also note that afterwards when trying to use typed Get (even if T is ulong) on that key (or normal Get) fails inside the Memcached client with type conversion error on line 119 in MemCachedClient.cs

This is serious issue please fix!!!

Owner

enyim commented Oct 29, 2011

you were never able to combine store+increment

in older version syou could exploit the way increment worked and you stored a string then incremented that key. the latest versions of memcached support setting a default value for non-existing keys, so there is no need for store.

if you want to reset, just remove the value.
if you need to start it from something else than 0 then use a default value.

@enyim enyim closed this Oct 29, 2011

Ok but why does typed GET fail then? How should I get the value back? Typed get should never fail. At least not in this way that it crashes Enyim Client

Also note that afterwards when trying to use typed Get (even if T is ulong) on that key (or normal Get) fails inside the Memcached
client with type conversion error on line 119 in MemCachedClient.cs

Owner

enyim commented Oct 29, 2011

if you do not mess with the counter previousl but use increment/decrement, you should be able to get it back as a string. either Get() or Get() should work

Ok but this issue is still not resolved since this is workaround and not resolution. Again typed Get should never fail. And definitely not like this...

Owner

enyim commented Oct 29, 2011

this is not a workaround, but how memcached handles counters. if you have issues with this, you have to take up with the memcached developers.

the server has no notion about longs and ints and such, it knows only about byte arrays and counters (whihc are converted into ascii by the server automatically)

I understand that but also I think that client should try to do conversion and not just casting here:

public T Get(string key)
{
object tmp;

return TryGet(key, out tmp) ? (T)tmp : default(T);
}

Why not use TypeConverter here?

Owner

enyim commented Oct 29, 2011

how would the client knew that you trying to retrieve a counter? only you know about your counters so you have to do the conversion.

Is there any news on this? I was having similar problems and after reading the linked issued from jbosse I am experiencing the same. Are we configuring something wrong or is there a problem with the client?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment