How to print all values in a list with redis-cli without knowing the size of the list?

22.2k views Asked by At

In redis-cli, what is the command to print all the values in a list without knowing in advance the size of the list? I see lrange, but it requires naming the start index and the end index.

2

There are 2 answers

0
Zitrax On BEST ANSWER

You use -1 to indicate end of list so:

LRANGE key 0 -1

would print all.

0
ajhowey On

Here's how I did it with python:

import redis
r_server = redis.Redis()
for num in "one", "two", "three", "four", "five":
    r_server.rpush("nums", num)

length = r_server.llen("nums")
for x in range(0,length):
    print(str(r_server.lindex("nums",x)))

b'one'
b'two'
b'three'
b'four'
b'five'