pythonredis

How can I parse a list result?


I am storing a list in Redis:

redis.lpush('foo', [1,2,3,4,5,6,7,8,9])

I get the list back like this:

redis.lrange('foo', 0, -1)

And I get this:

[b'[1, 2, 3, 4, 5, 6, 7, 8, 9]']

How can I convert this to an actual Python list? I don't see anything defined in RESPONSE_CALLBACKS that can help.


Solution

  • 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!