Redis list data type

Source: Internet
Author: User


List data type

List is a linked list structure, the main function is Push,pop, get all the values of a range and so on. In operation, key is understood as the name of the list, and the Redis list is actually a doubly linked list in which each child element is a string type, and we can add the deletion element from the head or tail of the list by Push,pop operation, so that the list can be both a stack and a queue



Lpush: Adding a string element to the list from the head


Example:

Lpush list1 ' Hello '

Lpush list1 ' World '

Lpush list1 ' ZJZ '


Lrange List1 0-2

Output: ZJZ World


Linsert insert at a specific location

Lpush List2 One

Lpush List2 Three

Linsert List2 before one outputs three-one head to front


LSet list2 0 ' AAA ' Replace the value of the element labeled 0 with AAA


Lrem List2 2 One removes two elements from the head, starting with the header (n<0 means delete from the tail, n=0 means delete all)



LTrim List2 1-1 retains elements of 1 to-1, all others removed


Lpop List2 pops an element from the head and returns the deleted element

Rpop List2 pops an element from the tail and returns the deleted element




Rpoplpush list1 list2 pop-up elements from List1 's tail and add to List2 's head


Lindex List1 1 Returns the value of the element labeled 1 in the List1, supporting negative numbers


Rpush list2 ' xxxx ' press in from the rear


Llen List2 Returns the length of the linked list


Redis list data type

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.