redis LSET command


  Translation results:

set

英[set] 美[sɛt]

vt. Set; place, arrange; put in a certain situation; place tableware

vi. Setting off; setting off; condensation

n.Gathering; a set; a set; a TV set

adj. Fixed; located in...; stubborn; arranged The

third person singular: sets plural: sets present participle: setting past tense: set past participle: set

redis LSET commandsyntax

Function: Set the value of the element whose subscript is index in the list key to value.

Syntax: LSET key index value

Description: When the index parameter is out of range, or LSET is performed on an empty list (key does not exist) , an error is returned.

Available versions: >= 1.0.0

Time complexity: Perform LSET operation on the head element or tail element, the complexity is O (1). In other cases, it is O(N), where N is the length of the list.

Return: Return ok if the operation is successful, otherwise an error message will be returned.

redis LSET commandexample

# 对空列表(key 不存在)进行 LSET
redis> EXISTS list
(integer) 0
redis> LSET list 0 item
(error) ERR no such key
# 对非空列表进行 LSET
redis> LPUSH job "cook food"
(integer) 1
redis> LRANGE job 0 0
1) "cook food"
redis> LSET job 0 "play game"
OK
redis> LRANGE job  0 0
1) "play game"
# index 超出范围
redis> LLEN list                    # 列表长度为 1
(integer) 1
redis> LSET list 3 'out of range'
(error) ERR index out of range

Home

Videos

Q&A