I am storing a list in Redis like this:
redis.lpush(\'foo\', [1,2,3,4,5,6,7,8,9])
And then I get the list back like this:
r
I think you're bumping into semantics which are similar to the distinction between list.append() and list.extend(). I know that this works for me:
myredis.lpush('foo', *[1,2,3,4])
... note the * (map-over) operator prefixing the list!
import json
r = [b'[1, 2, 3, 4, 5, 6, 7, 8, 9]']
rstr = r[0]
res_list = json.loads(rstr)
Another way: you can use RedisWorks
library.
pip install redisworks
>>> from redisworks import Root
>>> root = Root()
>>> root.foo = [1,2,3,4,5,6,7,8,9] # saves it to Redis as a list
...
>>> print(root.foo) # loads it from Redis later
It converts python types to Redis types and vice-versa. So even if you had nested list, it would have worked:
>>> root.sides = [10, [1, 2]] # saves it as list in Redis.
>>> print(root.sides) # loads it from Redis
[10, [1, 2]]
>>> type(root.sides[1])
<class 'list'>
Disclaimer: I wrote the library. Here is the code: https://github.com/seperman/redisworks