Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

LRANGE

Last updated
LRANGE key start stop
Group
List
Complexity
O(S+N) where S is the distance of start from the nearer end and N is the number of elements returned
Arity
4 (exactly, counting the command name)
Flags
read-only
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

LRANGE returns the elements of the list at key from index start to index stop, both included. Indexes start at 0. Negative indexes count from the end: -1 is the last element, -2 the one before it, and so on.

Out-of-range indexes are not an error. A stop past the end is treated as the last element, and a start past the end (or after stop) gives an empty array. LRANGE key 0 -1 returns the whole list.

Case RESP2 RESP3
Success Array of bulk strings Same
Key does not exist or the range is empty Empty array Same

Errors:

  • ERR value is not an integer or out of range if start or stop is not an integer. This is checked before the key is looked up.
  • WRONGTYPE if key holds a value that is not a list.
127.0.0.1:6379> RPUSH letters a b c d e
(integer) 5
127.0.0.1:6379> LRANGE letters 0 1
1) "a"
2) "b"
127.0.0.1:6379> LRANGE letters -2 -1
1) "d"
2) "e"
127.0.0.1:6379> LRANGE letters 3 100
1) "d"
2) "e"
127.0.0.1:6379> LRANGE letters 10 20
(empty array)

Same as Redis 7.4 and Valkey 8.

LINDEX, LLEN, LTRIM, LPOS