Latest web development tutorials

Redis Lindex command

Redis list (List)

Redis Lindex command is used to obtain a list of the elements by index. You can also use a negative index to -1 means the last element of the list, -2 represents the second to last element of a list, and so on.

grammar

redis Lindex basic command syntax is as follows:

redis 127.0.0.1:6379> LINDEX KEY_NAME INDEX_POSITION 

Available versions

> = 1.0.0

return value

List index for the element at the specified index value. If the index is specified within the range outside the scope of the list, returns nil.

Examples

redis 127.0.0.1:6379> LPUSH mylist "World"
(integer) 1

redis 127.0.0.1:6379> LPUSH mylist "Hello"
(integer) 2

redis 127.0.0.1:6379> LINDEX mylist 0
"Hello"

redis 127.0.0.1:6379> LINDEX mylist -1
"World"

redis 127.0.0.1:6379> LINDEX mylist 3        # index不在 mylist 的区间范围内
(nil)

Redis list (List)