w3resource

Redis Lists: LINDEX

LINDEX key index

Redis LINDEX command is used to get the element at index in the list stored at key. The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth.

Syntax:

redis 127.0.0.1:6379> LINDEX KEY_NAME INDEX_POSITION    

Available since

1.0.0.

Return Value

String reply, the requested element, or nil when the index is out of range.

Return Value Type

String

Example: Redis LINDEX

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> LINDEX mycolor1 0
"blue"
127.0.0.1:6379> LINDEX mycolor1 1
"red"
127.0.0.1:6379> LINDEX mycolor1 -1
"white"
127.0.0.1:6379> LINDEX mycolor1 -2
"black"
127.0.0.1:6379> LINDEX mycolor1 6
(nil)

Previous: BRPOPLPUSH
Next: LINSERT



Follow us on Facebook and Twitter for latest update.