YouTip LogoYouTip

Lists Linsert

# Redis Linsert Command [!(#) Redis Lists](#) The Redis Linsert command inserts an element before or after a specified element in a list. If the specified element does not exist in the list, no operation is performed. If the list does not exist, it is treated as an empty list, and no operation is performed. If the key is not of list type, an error is returned. ### Syntax The basic syntax of the Redis Linsert command is as follows: LINSERT key BEFORE|AFTER pivot value Inserts the value `value` into the list stored at `key`, before or after the element `pivot`. ### Available Versions >= 1.0.0 ### Return Value If the command executes successfully, it returns the length of the list after the insertion operation. 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 -11) "Hello"2) "There"3) "World" redis> [!(#) Redis Lists](#)
← Lists LlenLists Lindex β†’