can anybody tell me (or point to some documentation that documents) how memcached counters work? Specifically: how do they expire? I'm using the java spymemcached client.
The method
net.spy.memcached.MemcachedClient.incr(String key, int by, long def, int exp)
takes a parameter "exp" described as "the expiration of this object"
Does that mean each individual call to the counter has its own expiry time? Or does calling incr bump the expiry time for the key?
Also, shouldn't there be a method to get a counter value? Or should I call incr with an increment of 0?
The int exp
will overwrite the existing expiration time, and "bump" the key your incrementing. Check out the protocol docs for additional info.
Also, shouldn't there be a method to get a counter value? Or should I call incr with an increment of 0?
You can get the value of the counter cell by using MemcachedClient.get
method. The counter cell will need to be set from MemcachedClient.set
before you are able to increment it. I'm not 100% sure about spymemcached, but some memcached libraries will auto set the counter cell to 0 -- before incrementation.
A note on expiration time. If the int expr
is -1
memcached will use the previous expiration time. If int expr
is greater than 2592000
(30 days), it will be treated as an UNIX timestamp.