Series of articles:

What does redis do with simple dynamic string SDS

A List of what redis does at the bottom

What Hash is redis doing underneath

When the value of Redis is a List, the underlying implementation is a linked List, and you can add an element to the left or right side of the List

Redis linked list node implementation:

Is a bidirectional node. Multiple nodes can form a double-ended list using prev and next Pointers.

Redis list structure:

Although multiple nodes can form lists themselves, Redis uses a list structure to hold lists that are easier to operate:

A list structure with three nodes:

The head pointer points to the head node of the list

The tail pointer points to the last node of the list

lenRecords the number of nodes in the linked list

Redis List common operations

LPUSH

Inserts one or more values into the head of the list. Since it is inserted into the head, the data inserted later comes first

Grammar:

LPUSH key value [value ...]
Copy the code

RPUSH

Inserts one or more values to the end of the list, followed by the last value

Grammar:

RPUSH key value [value ...]
Copy the code

LRANGE

Check the value of the List corresponding to a key. Note that the value of this key must be of the List type. Otherwise, the WRONGTYPE Operation against a key holding the wrong kind of is displayed Value), the range of indexes to view must be set. The index of the List structure in Redis starts at 0

Grammar:

LRANGE key start stop
Copy the code

LPOP

Removes the head node of the linked list

Grammar:

LPOP key
Copy the code

RPOP

Remove the last node of the linked list

Grammar:

RPOP key
Copy the code

LINDEX

Gets the value of a node in the linked list by index

Grammar:

LINDEX key index
Copy the code

LLEN

Gets the length of a linked list

Grammar:

LLEN key
Copy the code

LTRIM

Take a linked list by index, get a part of it, and assign it to yourself

Grammar:

LTRIM key start stop
Copy the code

LSET

Sets the value of an index in the linked list

Grammar:

LSET key index value
Copy the code

SORT

Returns the result of the linked list in conditional order:

SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC]
Copy the code