I'm trying to store an object in redis, and when I get the object it doesn't seem to work.
I tried:
u = User.new
u.name = 'blankman'
$redis.set('test', u)
x = $redis.get('test')
x.name开发者_JAVA技巧 // error
I guess it is a serialization issue, do I have to do something special to my model for it to serialize?
I would suggest using the Marshal.dump
and Marshal.load
to serialize and deserialize objects respectively.
$redis.set 'key', (Marshal.dump object) #serialize
object = Marshal.load($redis.get 'key') #deserialize
As far as I know, redis will save a String representation of your object. So...
x.class # String
You have to use something to serialize/deserialize your objects when using Redis. Take a look at https://github.com/nateware/redis-objects
Kind Regards
精彩评论