Easy Tutorial
❮ Sets Smembers Scripting Eval ❯

Redis Lindex Command

Redis Lists

The Redis Lindex command is used to retrieve an element from a list by its index. You can also use negative indices, where -1 represents the last element of the list, -2 represents the second-to-last element, and so on.

Syntax

The basic syntax for 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 at the specified index in the list. If the specified index is out of range, it returns nil.

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 is out of range for mylist
(nil)

Redis Lists

❮ Sets Smembers Scripting Eval ❯