Reputation: 1160
I've saved a list into a hash but cannot figure out how to retrieve contents of the hash. Firstly, here is some code to create the list:
127.0.0.1:6379> LPUSH list1 'dc:39:79:ab:cd:ef'
(integer) 1
127.0.0.1:6379> LPUSH list1 '2014-07-21'
(integer) 2
127.0.0.1:6379> LPUSH list1 'Success'
(integer) 3
127.0.0.1:6379> LPUSH list1 'Miscellaneous notes about the install. Can be as long as you want'
(integer) 4
Now I create a hash and assign the value of one key to list1:
127.0.0.1:6379> hset hash 'RKT1234' list1
(integer) 1
How can I print the entire list saved inside hash['RKT1234'] ?
127.0.0.1:6379> hgetall hash
1) "RKT1234"
2) "list1"
127.0.0.1:6379> hvals hash 1) "list1"
thanks
Upvotes: 0
Views: 71
Reputation: 15773
It looks like you are attempting to store a list as a value in a hash. You are not doing what you think you are doing as Redis does not support nested data structures. In hset hash 'RKT1234' list1
you are not storing the list, just a string name: "list1".
In order to get the contents of list you need to first get the name of the list from the hash, then get the contents of the list in a second call.
So your sequence looks like this:
# returns "list1"
hvals hash
lrange list1 0 -1
# returns the contents of list1
Cheers
Upvotes: 1