Redis Linsert Command
The Redis Linsert command is used to insert an element before or after another element in the list. If the specified element does not exist in the list, no operation is performed.
When the list does not exist, it is treated as an empty list and no operation is performed.
If key is not of list type, returns an error.
Syntax
The basic syntax of the redis Linsert command is as follows:
LINSERT key BEFORE|AFTER pivot value
Insert value into list key either before or after the value pivot.
Available Version
= 1.0.0
Return Value
On success, returns the length of the list after the insertion. Returns -1 if the specified element is not found. Returns 0 if key does not exist or is an empty list.
Example
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>
Redis List