This is the 11th day of my participation in the August Wenwen Challenge.More challenges in August”

A Redis list is a simple list of strings, sorted in insertion order, with elements added to the left (head), right (tail), or middle.

Linked lists are extremely efficient both at the beginning and the end, but are much less efficient if they operate on intermediate elements.

The general idea of tab-type data operations is to operate on value by key and subscript. Key is the data identifier, subscript is the location of the data in the list, and value is the business data we are interested in.

Common commands

1, lpush

Lpush key value [value…]

Insert one or more values into the leftmost (header) of the list key.

Return value: The length of the inserted list.

2, rpush

Rpush key value [value…]

Insert one or more values to the right of the key (the end of the table).

Return value: The length of the inserted list.

3, lrange

Syntax: lrange key startIndex endIndex

Function: Obtain the elements in the specified subscript range in the list key, the subscript starts from 0 to the list length -1;

The subscript can also be negative to indicate that the list goes backwards, -1 for the penultimate element, -2 for the penultimate element, and so on;

StartIndex and endIndex are out of range.

Return value: list of retrieved elements.

4, lpop

Syntax: LPOP key

Function: Removes and returns the first element in the key header, the first element to the left of the list.

Return value: the value of the first element on the left of the list; List key does not exist, return nil.

5, rpop

Syntax: RPOP key

Removes and returns the first element at the end of the key, the first element to the right of the list.

Return value: the value of the first element on the right of the list; List key does not exist, return nil.

6, the lindex

Syntax: lindex key index

Function: Obtain the list key subscript of the specified index element, list elements do not delete, only query. 0 represents the first element of the list, 1 represents the second element of the list; Index can also be a negative index, -1 for the last element of the list, -2 for the next-to-last element of the list, and so on.

Return value: Returns the value of the specified element if key exists;

Return nil if Key does not exist.

7, llen

Syntax: llen key

Run the following command to obtain the length of a list key

Return value: numeric value, length of list; Return 0 if key does not exist

8 lrem.

Syntax: LREM key count value

Function: Remove elements equal to value from the list according to the value of parameter count.

Count >0, starting from left to right of the list;

Count < 0 is removed from the end of the list;

Count = 0 removes all values equal to value from the table.

Return value: number of elements removed

9, ltrim

Syntax: ltrim Key startIndex endIndex

Function: intercepts elements of the specified subscript range of the key, and assigns a value to the key. The subscript starts at 0 and goes all the way to list length -1;

The subscript can also be negative to indicate that the list goes backwards, -1 for the penultimate element, -2 for the penultimate element, and so on;

StartIndex and endIndex are out of range.

Return value: Ok is returned on success

10, lset

Syntax: lset key index value

Run the following command to set the key subscript index to value:

Function: Return OK after setting successfully; Key does not exist or index is out of range.

11, linsert

Syntax: Linsert key before/after pivot value

Function: Inserts the value value into the list key before or after the value pivot. Key does not exist or pivot is not in the list and does not perform any operations.

Return value: The length of the new list is returned on success. Pivot returns -1 not found, key does not exist to return 0.