Latest web development tutorials

Redis Linsert command

Redis list (List)

Redis Linsert command before or after inserting the elements of the list elements. When the specified element does not exist in the list, no action. When the list does not exist, is regarded as an empty list, no action is taken. If the key is not the type of list, an error is returned.

grammar

redis Linsert basic command syntax is as follows:

redis 127.0.0.1:6379> LINSERT KEY_NAME BEFORE EXISTING_VALUE NEW_VALUE 

Available versions

> = 1.0.0

return value

If, after the command is successful, the return insertion, the length of the list. If you do not find the specified element, or -1. If the key does not exist or is empty list, return 0.

Examples

redis 127.0.0.1:6379> RPUSH list1 "foo"
(integer) 1
redis 127.0.0.1:6379> RPUSH list1 "bar"
(integer) 2
redis 127.0.0.1:6379> LINSERT list1 BEFORE "bar" "Yes"
(integer) 3
redis 127.0.0.1:6379> LRANGE mylist 0 -1
1) "foo"
2) "Yes"
3) "bar"

Redis list (List)