English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Redis Linsert command is used to insert elements before or after the elements of the list. No operation is performed if the specified element does not exist in the list.
If the list does not exist, it is considered an empty list and no operation is performed.
If the key is not of list type, return an error.
The basic syntax of the redis Linsert command is as follows:
LINSERT key BEFORE|AFTER pivot value
Insert the value value into the list key, before or after the value pivot.
>= 1.0.0
If the command executes successfully, return the length of the list after the insertion operation. If the specified element is not found, return -1 . If the key does not exist or is an empty list, return 0.
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" redis>