LIST type of Redis data type, list type of redis Data Type

Source: Internet
Author: User

LIST type of Redis data type, list type of redis Data Type

Web programmer blog: http://blog.csdn.net/thinkercode

List type-Features

List is a linked list structure. The main function is to push, pop, get all values in a range, etc. In the operation, the key is interpreted as the name of the linked list.
The list type of Redis is actually a two-way linked list of the string type for each sub-element. The maximum length of a linked list is (2 to the power of 32 ). We can add and delete elements from the head or tail of the linked list through the push and pop operations. This allows the list to be used as both a stack and a queue.
Interestingly, the pop operation of the list has a blocking version. When we [lr] pop a list object, if the list is empty or does not exist, nil will be returned immediately. However, the blocked Version B [lr] pop can be blocked. Of course, the timeout time can be added, and nil will be returned after the timeout. Why is pop blocked? It is mainly used to avoid polling. A simple example is to use list to implement a work queue. The thread that executes the task can call the pop of the blocked version to obtain the task. This avoids polling to check whether a task exists. When a task comes, the worker thread can return immediately or avoid the delay caused by polling.

List type-application scenarios

Redis list has many application scenarios and is also one of Redis's most important data structures. For example, the Weibo follow list and fans list can all be implemented using the Redis list structure. In blog implementation, you can set a list for each log and push it into the blog comment. You can also use Redis list to Implement Message queue.
The data in the list is logically ordered (The table below the array). It is suitable for storing data with sequential characteristics (space and time attributes. For example, to record the user's browsing product id on the website, this time-based data can be used to analyze the user's shopping behavior.
As a queue, a list is added to one end to read data and the other end to read data. The most typical model is the producer/consumer model. For example, the second kill of a product can pop data from the initialized queue, until the queue is empty.
List is used as a stack. Only one end of the list is operated, and the data is first and then output.

List Common commands

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.