Easy Tutorial
❮ Pub Sub Publish Scripting Evalsha ❯

Redis Linsert Command

Redis Lists

The Redis Linsert command is used to insert an element before or after another element in a 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, an error is returned.

Syntax

The basic syntax for the redis Linsert command is as follows:

LINSERT key BEFORE|AFTER pivot value

Inserts the value before or after the pivot value in the list specified by key.

Available Versions

= 1.0.0

Return Value

If the command is successful, it returns the length of the list after the insertion. If the specified element is not found, it returns -1. If the key does not exist or the list is empty, it returns 0.

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 Lists

❮ Pub Sub Publish Scripting Evalsha ❯