redis LPUSHX command
Translation results:
push
UK[pʊʃ] US[pʊʃ]
vt.& vi. Push, push
vt. Press; push, increase; exert pressure on, force; persuade
n. push, determination; large-scale offensive; determined pursuit
vi. push; increase; strive for
Third person singular: pushes Present participle: pushing Past tense: pushed Past participle: pushed
redis LPUSHX commandsyntax
Function: Insert value value into the header of list key if and only if key exists and is a list. Contrary to the LPUSH command, the LPUSHX command does nothing when the key does not exist.
Syntax: LPUSHX key value
Available versions:>= 2.2.0
Time complexity : O(1)
Return: LPUSHX The length of the table after the command is executed.
redis LPUSHX commandexample
# 对空列表执行 LPUSHX redis> LLEN greet # greet 是一个空列表 (integer) 0 redis> LPUSHX greet "hello" # 尝试 LPUSHX,失败,因为列表为空 (integer) 0 # 对非空列表执行 LPUSHX redis> LPUSH greet "hello" # 先用 LPUSH 创建一个有一个元素的列表 (integer) 1 redis> LPUSHX greet "good morning" # 这次 LPUSHX 执行成功 (integer) 2 redis> LRANGE greet 0 -1 1) "good morning" 2) "hello"