Redis - List Lrange Command


Advertisements

Redis LRANGE command returns the specified elements of the list stored at the key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element, and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.

Return Value

Array reply, list of elements in the specified range.

Syntax

Following is the basic syntax of Redis LRANGE command.

redis 127.0.0.1:6379> LRANGE KEY_NAME START END

Example

redis 127.0.0.1:6379> LPUSH list1 "foo" 
(integer) 1 
redis 127.0.0.1:6379> LPUSH list1 "bar" 
(integer) 2 
redis 127.0.0.1:6379> LPUSHX list1 "bar" 
(integer) 0 
redis 127.0.0.1:6379> LRANGE list1 0 -1 
1) "foo" 
2) "bar" 
3) "bar"
redis_lists.htm
Advertisements