Redis command Details

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.