4

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!

Ahsan
  • 11,516
  • 12
  • 52
  • 79

2 Answers2

2

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.

Zubair Afzal
  • 2,016
  • 20
  • 29
0

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.

Michael Dillon
  • 31,973
  • 6
  • 70
  • 106