Inserts one or more value values into the table header of the list key
If there are multiple value values, then each value value is inserted in a left-to-right order into the table header: For example, for an empty list mylist execute Lpush mylist a b C, the result list is C B A, equivalent to executing the execution command
Lpush mylist A, Lpush mylist B, Lpush
MyList c.
If the key does not exist, an empty list is created and the Lpush operation is performed. An error is returned when key exists but is not a list type.
Annotations
Before the Redis 2.4 version of the Lpush command, only a single value value is accepted.
Available versions:
>= 1.0.0
Time complexity: O (1) return value:
The length of the list after the Lpush command is executed.
# Add a single element
redis> Lpush Languages Python
(integer) 1
# Add repeating elements
redis> Lpush Languages Python
(integer) 2
Redis> Lrange Languages 0-1 # list allows repeating elements
1) "Python"
2) "Python"
# Add multiple elements
Redis> Lpush MyList a b C
(integer) 3
redis> Lrange mylist 0-1
1) "C"
2) "B"
3) "A"
Inserts the value values into the table header of the list key when and only if key exists and is a list. As opposed to the Lpush command, when key does not exist, the LPUSHX command does nothing. Available versions:
>= 2.2.0 Time Complexity: O (1) return value:
The length of the table after the LPUSHX command executes.
# Execute lpushx on empty list
Redis> Llen Greet # greet is an empty list
(integer) 0
redis> lpushx Greet "Hello" # try Lpushx, failed because the list is empty
(integer) 0
# perform LPUSHX on a non-empty list
redis> lpush Greet "Hello" # first create a list with one element with Lpush
(integer) 1
Redis> lpushx greet "Good Morning" # this time Lpushx executed successfully
(integer) 2
Redis> Lrange greet 0-1
1) "Good Morning"
2) "Hello"
For more highlights, please follow: http://bbs.superwu.cn
Focus on the two-dimensional code of Superman Academy:
Redis command Details