Ahsan
Ahsan

Reputation: 11832

Python: get list of memcached key values by wildcards

I am using memcached with pylibmc as binaries in my Django app. Now what I want to get list of key values from cache.

Suppose I have this key value pair data in cache,

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

I can get a single record by

cache.get('Key_1')

I want to get all Key_*data

cache.get('Key_*')

Anyone suggest a way? or is it possible?

Thanks!

Upvotes: 4

Views: 4233

Answers (2)

Michael Dillon
Michael Dillon

Reputation: 32392

You could either use the mcdict library and iterate through memcached like a normal dictionary or else you could look at the mcdict source code and apply the same technique in your own code.

Upvotes: 0

Zubair Afzal
Zubair Afzal

Reputation: 2086

If you have dictionary than 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())

This way you can get all matching keys and then simply iterate on those keys.

Upvotes: 2

Related Questions