English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Lindex Command

Redis Lists (List)

The Redis Lindex command is used to retrieve elements from the list by index. You can also use negative indices to, -1 Represents the last element in the list, -2 Represents the second-to-last element in the list, 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 Version

>= 1.0.0

Return Value

The element at the specified index in the list. If the specified index value is not within the range of the list, return nil.

Online 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        The index is not within the range of mylist
(nil)

Redis Lists (List)