Easy Tutorial
❮ Strings Psetex Redis Sets ❯

Redis Lrange Command

Redis Lists

Redis Lrange returns the elements within the specified range of a list, with the range defined by the offsets START and END.

Here, 0 represents the first element of the list, 1 represents the second element, and so on.

You can also use negative indices, where -1 indicates the last element of the list, -2 indicates the second-to-last element, and so on.

Syntax

The basic syntax for 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 the 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 Lists

❮ Strings Psetex Redis Sets ❯