LINDEX
Syntax
LINDEX key index
- Available since:
- 1.0.0
- Time complexity:
- O(N) where N is the number of elements to traverse to get to the element at index. This makes asking for the first or the last element of the list O(1).
- ACL categories:
-
@read
,@list
,@slow
,
返回存储在key
中的列表中索引为index
的元素。
索引从零开始,因此0
表示第一个元素,1
表示第二个元素,依此类推。
负索引可用于指定从列表尾部开始的元素。
在这里,-1
表示最后一个元素,-2
表示倒数第二个元素,依此类推。
当key
处的值不是列表时,将返回错误。
示例
RESP2 回复
以下之一:
- Nil reply: 当 index 超出范围时。
- Bulk string reply: 请求的元素。
RESP3 回复
以下之一:
- Null reply: 当 index 超出范围时。
- Bulk string reply: 请求的元素。