Redis list(List)
Redis list is a simple list of strings, sorted in insertion order. You can add an element to the head (left) or tail (right) of a list
A list can contain up to 232 - 1 elements (4294967295, more than 4 billion elements per list).
Example
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 the list named w3ckey.
Redis list command
The following table lists the basic commands related to the list:
##6LLEN key 7LPOP key 8LPUSH key value1 [value2] 9LPUSHX key value 10LRANGE key start stop 11LREM key count value 12LSET key index value 13LTRIM key start stop 14RPOP key 15RPOPLPUSH source destination 16RPUSH key value1 [value2 ] 17RPUSHX key valueSerial number | Command and Description |
---|---|
1 | BLPOP key1 [key2 ] timeout Remove and get the first element of the list. If there are no elements in the list, the list will be blocked until the wait times out or Until popupable elements are found. |
2 | BRPOP key1 [key2 ] timeout Remove and get the last element of the list. If there is no element in the list, the list will be blocked until the wait times out or an available element is found. until the element pops up. |
3 | BRPOPLPUSH source destination timeout Pop a value from the list, insert the popped element into another list and return it; if the list does not The element blocks the list until the wait times out or until a poppable element is found. |
4 | LINDEX key index Get elements in the list by index |
5 | LINSERT key BEFORE|AFTER pivot value Insert elements before or after the elements of the list |
Get the length of the list | |
Move out and get the first element of the list | |
Insert one or more values into the head of the list | |
Insert one or more values into the head of the list Insert into the head of an existing list | |
Get elements within the specified range of the list | |
Remove list elements | |
Set by index The value of the list element | |
Trim a list, that is, let the list retain only the elements within the specified range Elements that are not within the specified range will be deleted. | |
Remove and get the last element of the list | |
Remove the last element of the list and add that element to another list and return | |
Add one or more values to the list | |
Add a value to an existing list |