redis LINSERT command


  Translation results:

insert

UK[ɪnˈsɜ:t] US[ɪnˈsɜ:rt]

vt.Insert; embed; (in the article) add; insert

n. Insertion; addition (especially a small picture inserted or overprinted in a printed page); (book or newspaper) insert; addition

Third person singular: inserts now Participle: inserting Past tense: inserted Past participle: inserted

redis LINSERT commandsyntax

Function: Insert the value value into the list key, before or after the value pivot.

Syntax: LINSERT key BEFORE|AFTER pivot value

Description: When pivot does not exist in the list key, no operation is performed. When key does not exist, key is treated as an empty list and no operation is performed. If key is not a list type, an error is returned.

Available versions: >= 2.2.0

Time complexity: O(N), N is the number of times passed in the process of finding pivot Number of elements.

Return: If the command is executed successfully, return the length of the list after the insertion operation is completed. If pivot is not found, -1 is returned. If key does not exist or is an empty list, 0 is returned.

redis LINSERT commandexample

redis> RPUSH mylist "Hello"
(integer) 1
redis> RPUSH mylist "World"
(integer) 2
redis> LINSERT mylist BEFORE "World" "There"
(integer) 3
redis> LRANGE mylist 0 -1
1) "Hello"
2) "There"
3) "World"
# 对一个非空列表插入,查找一个不存在的 pivot
redis> LINSERT mylist BEFORE "go" "let's"
(integer) -1                                    # 失败
# 对一个空列表执行 LINSERT 命令
redis> EXISTS fake_list
(integer) 0
redis> LINSERT fake_list BEFORE "nono" "gogogog"
(integer) 0                                      # 失败

Home

Videos

Q&A