Redis Lindex Command
The Redis Lindex command is used to retrieve an element from a list by its index. You can also use negative indexes, with -1 representing the last element of the list, -2 representing the second-to-last element, and so on.
Syntax
The basic syntax of the Redis Lindex command is as follows:
redis 127.0.0.1:6379> LINDEX KEY_NAME INDEX_POSITION
Available Versions
>= 1.0.0
Return Value
The element in the list at the specified index. If the specified index is outside the range of the list, nil is returned.
Example
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)Other Extensions
Redis Lists