Redis lists (list)

Source: Internet
Author: User

The Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head of the list (left) or tail (right)

A list can contain up to 232-1 elements (4294967295, more than 4 billion elements per list).

Instance
  1. Redis 127.0. 0.1:6379> lpush w3ckey redis
  2. (integer) 1
  3. Redis 127.0. 0.1:6379> lpush w3ckey mongodb
  4. (integer) 2
  5. Redis 127.0. 0.1:6379> lpush w3ckey mysql
  6. (integer) 3
  7. Redis 127.0. 0.1:6379> lrange w3ckey 0
  8. 1) "MySQL"
  9. 2) "MongoDB"
  10. 3) "Redis"

In the above example we used Lpush to insert three values into the list named W3ckey.

Redis List command

The following table lists the basic commands related to the list:

Serial Number Command and Description
1 Blpop key1 [Key2] timeout moves out and gets the first element of the list, and if no element of the list blocks the list until the wait time out or the popup element is found.
2 Brpop key1 [Key2] timeout moves out and gets the last element of the list, if no element of the list blocks the list until the wait time-out or the popup element is found.
3 Brpoplpush Source Destination timeout pops a value from the list, inserts the popup element into another list, and returns it, if no element of the list blocks the list until the wait time-out or the popup element is found.
4 LINDEX key index Gets the elements in the list by index
5 Linsert Key before| After pivot value inserts an element before or after the element in the list
6 Llen Key Get list length
7 Lpop key moves out and gets the first element of the list
8 Lpush key value1 [value2] inserts one or more values into the list header
9 Lpushx key value inserts one or more values into the list header that already exists
10 Lrange key start stop gets the list of elements in the specified range
11 Lrem Key Count value Remove list element
12 LSET Key index value sets the values of the list elements by index
13 LTRIM key start stop trims a list (trim), which means that the list retains only the elements within the specified interval, and the elements that are not within the specified range are deleted.
14 Rpop key to remove and get the last element of the list
15 Rpoplpush source destination Removes the last element of the list and adds the element to another list and returns
16 Rpush key value1 [value2] adds one or more values to the list
17 Rpushx key value adds a value to a list that already exists

Redis lists (list)

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.