ruby - Setting array as hash's value in Redis -
i'm using redis ruby , i'd redis make hash in value array. however, array value key, value key (shortly - hash in hash).
arr = ["this", "is", "an", "array"] r = redis.new r.hset("super_key", "key", arr)
which gives me error: err wrong number of arguments 'hset' command
.
i'd expect hash this:
{ "super_key" => { "key" => ["this", "is", "an", "array"] } }
so correct way of performing action?
not 100% sure what's making method angry, you're using in way doesn't allow. the redis gem documentation:
redis stores strings values. if want store object, can use serialization mechanism such json...
so try storing array.to_json
, , use json.parse(obj)
again.
Comments
Post a Comment