Redis Learning Note (11)--redis Common operation instruction (ii)

Source: Internet
Author: User
Tags redis
list lists common directives

List is a data structure of single value and multiple value
Lpush key value [value]

Here the L is left meaning, one or more value values are inserted into the table header of the list key, and if there are multiple values, then the header is inserted in the right-to-bottom form, for example, insert 1 2 3, the storage structure is 3 2 1 (table header to footer)

Rpush key value [value]

Here r is the meaning of right, inserting one or more value values into the table header of the list key, and if there are multiple values, insert the header into the table, in turn, to the left, for example, insert 1 2 3, the storage structure is 1 2 3 (header to footer)

Lrange Key Start stop

Get list content based on start subscript and end subscript, 0-1 get all, next we look at MyList and mylist01


You can see that Lpush is really positive in reverse, and Rpush is how to get in.

Lpop Key

Lpop is the stack operation, delete the top elements of the stack, mylist and mylist01 stack top elements are 5 and 1 respectively, we verify

That's true.

Rpop Key

Rpop is also out of the stack operation, but he is to delete the stack tail elements, mylist and mylist01 stack tails are 1 and 5 respectively, verify

Lindex Key

The l here is shorthand for list, do not mix with Lpush and Lpop L, get elements by index subscript (top to bottom)
After our previous operation, mylist = [4,3,2],mylist01 = [2,3,4], using lindex to get the element labeled 0

Llen

Get the length of a list

Lrem Key Count value

REM is the shorthand for remove, removing multiple identical values from the list, for example, to define a mylist02 = [1 1 1 1 2 2 2 3 3 3]
Delete 2 x 1

You can see that the modified list has been deleted by two of the 1

LTrim Key Start stop

Gets the value of the specified range and assigns the value to key, such as the current mylist02 = [1 1 2 2 2 3 3 3]

Note that the scope of interception here is about the

Rpoplpush Source list Destination List

Remove the stack tail element of the source list, add to the Stack top (table header) of the destination list, for example mylist01 = [2 3 4],mylist02 = [2 2 2 3], we use mylist01 as the source list, mylist02 as the destination list, after Rpoplpush, The results are as follows

It really is inserting the 4 element into the top of mylist02 's stack.

LSet Key index value

Specify the value of the cursor in the Modify list

Linsert Key before Value1 value2

Inserts a value before the value specified by the given list

Linsert key after value1 value2

Inserts a value after the value specified in the given list
Performance Summary

1, the Redis list is a string linked list, left,right can be inserted add
2, if the key does not exist, create a new list
3, if the key already exists, new
4, if the value is removed, the corresponding key disappears
5, The operation of a linked list is extremely efficient both in terms of head and tail, but if you operate on intermediate elements, the efficiency is not very high

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.