Redis database of 03_NoSQL Database: list type, 03_nosqlredis
Zookeeper
Lists type and Operation
List is a linked List structure. The main function room is 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 with every element of the string type. We can add and delete elements from the head or tail of the linked list through the push and pop operations, so that the list can be both a stack and a queue.
Lpush: Add a string element to the header of the list corresponding to the key.
Rpush: Add a string element at the end of the list corresponding to the key.
Linsert: Add a string before or after a specific position of the key corresponding to the list.
Lset: set the value of the element specified in the list object.
Lrem: deletes n elements with the same value from the list corresponding to the key. (N <0 is deleted from the end, n = 0 is all deleted)
The above lrem mylist5 1 "hello" indicates that the same value as hello is deleted from mylist5.
The number returned above indicates the number of deletions.
Ltrim: retains data within the value range of the specified key.
For example, ltrim list8 1-1 indicates that the value of the subscript from 1 to the last element is retained, and all other elements are deleted.
Lpop: deletes an element from the list header and returns the deletion element.
Rpop list10
Lrange list10 0-1
Rpoplpush: Removes elements from the end of the first list and adds them to the header of the second list.
Rpoplpush mylist5 mylist6 indicates that the elements in mylist5 are popped up and sent to mylist6.
Check mylist5 and find that there is only one three. Then, check mylist6 and find that there are three elements: hello, hello, foo.
Lindex: returns the index position element in the list named key.
Llen: view the number of elements in the linked list