allen8807 / memcached

Automatically exported from code.google.com/p/memcached
0 stars 0 forks source link

memcached Counter #229

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I installed memcached server in linux
and I run this java code:

MemCachedClient mc = new MemCachedClient();
        String key   = "counterKey";
        long i = 10;
        mc.storeCounter(key, 1);
        System.out.println(mc.incr(key, 1));
        System.out.println(mc.incr(key, 1));
        System.out.println(mc.get(key));
        System.out.println(mc.getCounter(key));

result is
-1
-1
10
-1

why??

Original issue reported on code.google.com by litiey...@gmail.com on 24 Oct 2011 at 9:16

GoogleCodeExporter commented 9 years ago

Original comment by ingen...@gmail.com on 24 Oct 2011 at 10:31

GoogleCodeExporter commented 9 years ago
What client is this with?  I think it may be something rather ancient.

With the Whalin Memcached-Java-Client, and this (more correct) code, I get 
something similar.  Seems like a client bug, but I'm not certain.

    public static void main(String[] args) {
        MemcachedClient mc = new MemcachedClient();
        String key   = "counterKey";
        mc.storeCounter(key, 10L);
        System.out.println(mc.incr(key, 1L));
        System.out.println(mc.incr(key, 1L));
        System.out.println(mc.get(key));
        System.out.println(mc.getCounter(key));

-1
-1
null
-1

With correct code using the spymemcached client, I get expected results.

        spymc.set("spy" + key, 0, "10");
        System.err.println(spymc.get("spy" + key));
        System.err.println(spymc.incr("spy" + key, 1L));
        System.err.println(spymc.incr("spy" + key, 1L));
        System.err.println(spymc.get("spy" + key));

10
11
12
12

In any event, it appears to not be a server bug.

Original comment by ingen...@gmail.com on 25 Oct 2011 at 12:32