LINDEX
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.
Return value
Section titled “Return value”| 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:
WRONGTYPEifkeyholds a value that is not a list.ERR value is not an integer or out of rangeifindexis not an integer. The key is looked up first, so a missing key replies nil even for a bad index.
Examples
Section titled “Examples”127.0.0.1:6379> RPUSH letters a b c(integer) 3127.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)Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.