To get a key from memcache (using pylibmc), you do this:
client.set(key, {'object': 'dictionary'}, time=expire)
client.get(key)
The same in redis is this:
redis.setex(key, expire, {'object': 'dictionary'})
eval(redis.get(key) or 'None')
That last line doesn't look right to me. redis only seems to return strings. Is there a get redis to return the object in the same form that it was put in?
The difference is that while both memcached and redis only support string values,
pylibmc
serializes the values you send it usingpickle
,redis-py
just converts them to string.If you want to do the same with redis, you can have your own functions to do the pickling for you.
Or you can even subclass Redis:
Courtesy: https://github.com/andymccurdy/redis-py/issues/186