LRANGE
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.
Return value
Section titled “Return value”| 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 rangeifstartorstopis not an integer. This is checked before the key is looked up.WRONGTYPEifkeyholds a value that is not a list.
Examples
Section titled “Examples”127.0.0.1:6379> RPUSH letters a b c d e(integer) 5127.0.0.1:6379> LRANGE letters 0 11) "a"2) "b"127.0.0.1:6379> LRANGE letters -2 -11) "d"2) "e"127.0.0.1:6379> LRANGE letters 3 1001) "d"2) "e"127.0.0.1:6379> LRANGE letters 10 20(empty array)Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.