Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

LINDEX

Last updated
LINDEX key index
Group
List
Complexity
O(N) where N is the distance of the index from the nearer end
Arity
3 (exactly, counting the command name)
Flags
read-only
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

LINDEX returns the element at position index of the list stored at key. Indexes start at 0; negative indexes count from the end, so -1 is the last element.

Case RESP2 RESP3
Index in range Bulk string: the element Same
Index out of range, or key does not exist Nil bulk string Null

Errors:

  • WRONGTYPE if key holds a value that is not a list.
  • ERR value is not an integer or out of range if index is not an integer. The key is looked up first, so a missing key replies nil even for a bad index.
127.0.0.1:6379> RPUSH letters a b c
(integer) 3
127.0.0.1:6379> LINDEX letters 0
"a"
127.0.0.1:6379> LINDEX letters -1
"c"
127.0.0.1:6379> LINDEX letters 5
(nil)

Same as Redis 7.4 and Valkey 8.

LSET, LRANGE, LPOS, LLEN