Python: get list of memcached key values โ€‹โ€‹using wildcards

I am using memcached with pylibmc as executables in my Django application. Now I want to get a list of key values โ€‹โ€‹from the cache.

Suppose I have data for this key value pair in the cache,

 {'Key_1':[1,2,3]} {'Key_2':[4,5,6]} {'Key_3':[6,7,8]} 

I can get one entry

 cache.get('Key_1') 

I want to get all Key_* data

 cache.get('Key_*') 

Does anyone suggest a way? or is it possible?

Thanks!

+4
source share
2 answers

If you have a dictionary, you can do something like this:

 import re dict = { 'Key_1':[1,2,3], 'Key_2':[4,5,6], 'Key_3':[6,7,8] } r = re.compile(r"Key_\d+") // matching expression matching_keys = filter(r.match, dict.keys()) 

That way you can get all the relevant keys, and then just iterate over those keys.

+2
source

You can use the mcdict library and mcdict through memcached as a regular dictionary, otherwise you can look at the mcdict source code and apply the same technique in your own code.

0
source

All Articles