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:
Serial 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 |
LLEN key | Get the length of the list |
LPOP key | Move out and get the first element of the list |
LPUSH key value1 [value2] | Insert one or more values into the head of the list |
LPUSHX key value | Insert one or more values into the head of the list Insert into the head of an existing list |
LRANGE key start stop | Get elements within the specified range of the list |
LREM key count value | Remove list elements |
LSET key index value | Set by index The value of the list element |
LTRIM key start stop | 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. |
RPOP key | Remove and get the last element of the list |
RPOPLPUSH source destination | Remove the last element of the list and add that element to another list and return |
RPUSH key value1 [value2 ] | Add one or more values to the list |
RPUSHX key value | Add a value to an existing list |