w3resource

Redis Lists: LRANGE

LRANGE key start stop

Redis LRANGE command is used to return the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on.

Syntax:

LRANGE KEY_NAME START END     

Available since

1.0.0.

Return Value

Array reply, a list of elements in the specified range.

Return Value Type

Array

Example: Redis LRANGE

127.0.0.1:6379> LPUSH mycolor1 white black red blue
(integer) 4
127.0.0.1:6379> LRANGE mycolor1 0 -1
1) "blue"
2) "red"
3) "black"
4) "white"
127.0.0.1:6379> LRANGE mycolor1 0 1
1) "blue"
2) "red"
127.0.0.1:6379> LRANGE mycolor1 2 -1
1) "black"
2) "white"

Example: Redis LRANGE: using negative right data

127.0.0.1:6379> LRANGE mycolor1 -2 -1
1) "black"
2) "white"
127.0.0.1:6379> LRANGE mycolor1 -4 -3
1) "blue"
2) "red"
127.0.0.1:6379> LRANGE mycolor1 0 -3
1) "blue"
2) "red"

Example: Redis LRANGE: Range error does not occur

127.0.0.1:6379> LRANGE mycolor1 3 20
1) "white"
127.0.0.1:6379> LRANGE mycolor1 -20 -10
(empty list or set)

Previous: LSET
Next: LTRIM



Follow us on Facebook and Twitter for latest update.