What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

LINSERT

Inserts an element before or after another element in a list.

Usage
LINSERT key where pivot element
Complexity
O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N).
Since
2.2.0
ACL Categories
@list, @slow, @write
Command flags
WRITE, DENYOOM

Inserts element in the list stored at key either before or after the reference value pivot.

When key does not exist, it is considered an empty list and no operation is performed.

An error is returned when key exists but does not hold a list value.

Examples

127.0.0.1:6379> RPUSH mylist "Hello"
(integer) 1
127.0.0.1:6379> RPUSH mylist "World"
(integer) 2
127.0.0.1:6379> LINSERT mylist BEFORE "World" "There"
(integer) 3
127.0.0.1:6379> LRANGE mylist 0 -1
1) "Hello"
2) "There"
3) "World"

Replies

RESP2

One of the following:

RESP3

One of the following: