Listing all keys on a server: why?

Jacob Coby jcoby at listingbook.com
Thu Jul 27 18:31:00 UTC 2006


Jamie McCarthy wrote:
> Hi everyone,
> 
> Every once in a while I hear people musing that it'd be useful to get a
> list of all keys currently available in a memcached server.  If you're
> one of those people, please email me off-list, I'd like to kick ideas
> around with you.
> 
> My current thinking is that, since:
> 
> * one or more memcached servers may be down when you get your list
>   and come back up immediately afterwards
> * whatever you want the list for, it's not atomic with your next
>   memcached operation anyway
> 
> ...the list you would get would be obsolete as soon as you got it.  So
> my guess would be that, if you think you need that list, you may be
> wanting to do something with memcached that you can't really do.  But my
> guesses are frequently wrong and if there's something I'm forgetting
> please email me and let me know.  Thanks.

I think a lot of that comes from the lack of namespaces in memcached. 
You can't just say 'invalidate all cache entries for user jsmith.'  So, 
an obvious way to work around it is to get a list of active keys, run 
through them looking for anything that matches 'jsmith' and delete it.

Sure, you could do a flush_all, but some people truly cannot afford to 
refill their cache due to the thundering herd.

As a matter of fact, the lack of namespaces or the ability to enumerate 
keys is preventing me from using memcached in several situations because 
I need to be able to invalidate cache entries for listings as they come 
into our system.

Another solution is to allow wildcards in some ops.  At least then you'd 
be able to 'delete jsmith*'.  Sure, it'd be an O(n) op, but that's 
better than nothing.

--
-Jacob



More information about the memcached mailing list