Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Redis List


May 16, 2021 Redis


Table of contents


Redis List

The Redis list is a simple list of strings, sorted in the order in which they were inserted. Y ou can add the head (left) or tail (right) of an element guide list

A list can contain up to 232 - 1 element (4294967295, more than 4 billion elements per list).

Instance

redis 127.0.0.1:6379> LPUSH w3ckey redis
(integer) 1
redis 127.0.0.1:6379> LPUSH w3ckey mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH w3ckey mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE w3ckey 0 10

1) "mysql"
2) "mongodb"
3) "redis"

In the above example, we used LPUSH to insert three values into a list called w3ckey.

Redis list command

The following table lists the basic commands related to the list:

Serial number Commands and descriptions
1 BLPOP key1 [key2 ] timeout
Move out and get the first element of the list, and if there are no elements in the list, the list is blocked until you wait for the timeout or find a pop-up element.
2 BRPOP key1 [key2 ] timeout
Move out and get the last element of the list, and if there are no elements in the list, block the list until you wait for the timeout or find a pop-up element.
3 BRPOPLPUSH source destination timeout
Pop a value from the list, insert the pop-up element into another list, and return it;
4 LINDEX key index
Get the elements in the list through the index
5 LINSERT key BEFORE| AFTER pivot value
Insert elements before or after the elements of the list
6 LLEN key
Gets the length of the list
7 LPOP key
Move out and get the first element of the list
8 LPUSH key value1 [value2]
Insert one or more values into the list header
9 LPUSHX key value
Insert one or more values into an existing list header
10 LRANGE key start stop
Gets the elements within the specified range of the list
11 LREM key count value
Remove the list element
12 LSET key index value
The value of the list element is set by indexing
13 LTRIM key start stop
Trim a list by keeping only the elements within the specified interval, and elements that are not within the specified interval are deleted.
14 RPOP key
Remove and get the last element of the list
15 RPOPLPUSH source destination
Remove the last element of the list and add the element to another list and return it
16 RPUSH key value1 [value2]
Add one or more values to the list
17 RPUSHX key value
Add a value to an existing list