28

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.

Arun Karunagath
  • 1,593
  • 10
  • 24
einnocent
  • 3,567
  • 4
  • 32
  • 42

2 Answers2

59

You use -1 to indicate end of list so:

LRANGE key 0 -1

would print all.

Zitrax
  • 19,036
  • 20
  • 88
  • 110
0

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'
ajhowey
  • 41
  • 4