List is a linked list structure, the main function is Push,pop, get a range of all values and so on, the operation of key can be understood as the name of the list.
The Redis list type is actually a doubly linked list where each child element is a string type, and we can operate from the list with the Push,pop command
The head or tail of the add delete element, so that the list can be both as a stack, but also as a queue.
List common operations:
(1) Lpush and Rpush
Lpush indicates that a string element is added to the head of the list corresponding to the key. Example: Lpush list Hello
The Rpush indicates that a string element is added at the end of the list corresponding to the key. Example: Rpush list World
(2) Lpop and Rpop
The lpop represents the element removed from the head of the list and returns the element.
The rpop represents the element removed from the head of the list and returns the element.
(3) Lrange
Removes the element within the specified range. For example: Lrange list 0-1,0 is the subscript for the first element, and 1 is the subscript for the last element.
(4) Linsert
Add a string before or after the specific position of the list for the key, for example:
Linsert list before Hello Redis indicates that an element is inserted in front of hello in the list link Redis
(5) LSet
Sets the element value for the specified subscript in the list, for example: LSet list 1 Database, which means to replace the element in list 1 with
Database.
(6) Lrem
Deletes the N and value elements from the list of key, and if N<0 is removed from the tail, n=0 means delete all.
Example: Lrem list 1 Hello
(7) LTrim
Retains data within the specified key range. For example: LTrim list 1-1, which is equivalent to preserving only the values of the following table from 1 to the last element.
(8) Rpoplpush
Removes the element from the tail of the first list and adds it to the head of the second list. For example:
(9) Lindex
Returns the element in the list with the name key as the index position. For example: Lindex list 1, returns the element labeled 1 in the list.
(Ten) Llen
Returns the length of the key corresponding to the list.
Redis database (list type)