Redis Lrange Command

Redis List

Redis Lrange returns the elements in the specified range within the list, where the range is specified by offsets START and END. Here, 0 indicates the first element of the list, 1 indicates the second element, and so on. You can also use negative subscripts, where -1 represents the last element of the list, -2 represents the second-to-last element, and so on.

Syntax

The basic syntax of the redis Lrange command is as follows:

redis 127.0.0.1:6379> LRANGE KEY_NAME START END

Available Versions

>= 1.0.0

Return Value

A list containing elements within the specified range.

Example

redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> LRANGE mylist 0 0
1) "one"
redis> LRANGE mylist -3 2
1) "one"
2) "two"
3) "three"
redis> LRANGE mylist -100 100
1) "one"
2) "two"
3) "three"
redis> LRANGE mylist 5 10
(empty list or set)
redis> 

Redis List

Other Extensions