I'm trying to store a custom, serializable python object in Redis, but have encountered some strange behavior. The set
method seems to function, but the get
method only returns the value of the object's __repr__
method. For instance...
import redis
# initialize the redis connection pool
rs = redis.Redis(host='localhost', port=6379)
# define a custom class
class SomeCustomObject(object):
pass
When I try to set the SomeCustomObject
as a value, it appears to work:
>>> rs.set('c', SomeCustomObject())
True
However, when I get
the value back, it's just the __repr__
string:
>>> rs.get('c')
'<__main__.SomeCustomObject object at 0x102496710>'
How do I store/get the instance back? I've not had much luck finding any info on this in the documentation, but surely I'm not the first one to encounter this?