cachedump time is not expiry time... but key set time?

437 views
Skip to first unread message

Bluntcoder

unread,
Apr 6, 2011, 8:17:37 PM4/6/11
to memcached
Hello,

I'm trying to write a tool that will show all the data inside
memcached, including expiry times of the keys. However I have run into
a big of a snag. It seems that the cache dump expiry times are lying
to me - or I'm not understanding what they do.

Here's my experiment. In a php file, I do the following:

1) I set a key "foo" to expire in 200 seconds.
2) I use get stats to get the current time of the memcached server,
Unix epoch format.
3) I do a cache dump which retrieves all keys, and their expiration
times, in Unix epoch format.

I find foo in the cache dump list and subtract the server time from
the expiry time. I expect it to be close to 200 (maybe 199 for network
lantecy or something).

But instead I get -1, or sometimes 0. Based on the other key values
that were collected, and the fact the difference keeps on growing, I
am left to assume that the number in cache dump is *not* the expiry
time, but the time that the key was set.

Could anyone from memcached confirm this? If this is true, is it
possible to retrieve the expiry time per key, somehow?

Thanks,
Mark

tony Cui

unread,
Apr 8, 2011, 6:54:50 AM4/8/11
to memc...@googlegroups.com, Bluntcoder
Hi All,

when you put data into the memcached, why there is a time limit. What about you do not use the expiration, does it work?



Thanks
Tony
--
tony.cui
happy new year

Abioy Sun

unread,
Apr 8, 2011, 9:46:45 PM4/8/11
to memc...@googlegroups.com
Hello,

2011/4/7 Bluntcoder <mik...@gmail.com>:


> Hello,
>
> I'm trying to write a tool that will show all the data inside
> memcached, including expiry times of the keys. However I have run into

Well, I make a tool for the same purpose as well (
http://www.cnblogs.com/sunyongyue/archive/2011/04/01/memcached_key_traversal.html
), but then found the fact that 'stats cachedump' has a limit echo
buffer memory up to 2MB and won't be able to return all items if
there is too many.

> that were collected, and the fact the difference keeps on growing, I
> am left to assume that the number in cache dump is *not* the expiry
> time, but the time that the key was set.

That base on the version you have, see the source code below.
typedef struct _stritem {
……
rel_time_t time; /* least recent access */
rel_time_t exptime; /* expire time */
……
} item;

// in 1.2.1, use 'least recent access'
len = sprintf(temp, "ITEM %s [%u b; %lu s]\r\n", ITEM_key(it),
it->nbytes - 2, it->time + stats.started);

// in 1.4.5, use 'expire time'
len = snprintf(temp, sizeof(temp), "ITEM %s [%d b; %lu s]\r\n",
key_temp, it->nbytes - 2,
(unsigned long)it->exptime + process_started);
best regards
--
Abioy

Abioy Sun

unread,
Apr 8, 2011, 9:54:02 PM4/8/11
to memc...@googlegroups.com
Hello,

2011/4/8 tony Cui <anyone...@gmail.com>:


> Hi All,
> when you put data into the memcached, why there is a time limit. What about
> you do not use the expiration, does it work?

I guess that's the protocol memcached has, and you have to follow the
rules in order to communicate with it, see the text below from
memcached protocol.
"
- <exptime> is expiration time. If it's 0, the item never expires
(although it may be deleted from the cache to make place for other
items). If it's non-zero (either Unix time or offset in seconds from
current time), it is guaranteed that clients will not be able to
retrieve this item after the expiration time arrives (measured by
server time).
"

tony Cui

unread,
Apr 8, 2011, 10:12:49 PM4/8/11
to memc...@googlegroups.com, Abioy Sun
Thank you very much Abioy Sun, 

Best regards
Tony Cui
--
Best Regards
Tony Cui

330.gif
Reply all
Reply to author
Forward
0 new messages