Redis lists (list)
The Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head of the list (left) or tail (right)
A list can contain up to 232-1 elements (4294967295, more than 4 billion elements per list).
Instance
Redis127.0.0.1:6379>Lpush Runoobkey Redis(Integer) 1Redis127.0.0.1:6379>Lpush Runoobkey MongoDB(Integer) 2Redis127.0.0.1:6379> Lpush runoobkey MySQL (integer) 3 redis 127.0. 0.1:6379> Lrange Runoobkey 0 101 "MySQL" 2 "MongoDB" 3 "Redis"
In the above example we used Lpush to insert three values into the list named Runoobkey .
Redis List command
The following table lists the basic commands related to the list:
| Serial Number |
Command and Description |
| 1 |
Blpop key1 [Key2] Timeout Moves out and gets the first element of the list, if no elements of the list block the list until the wait time-out or the popup element is found. |
| 2 |
Brpop key1 [Key2] Timeout Moves out and gets the last element of the list, if no element of the list blocks the list until the wait time-out or the popup element is found. |
| 3 |
Brpoplpush Source Destination Timeout POPs a value from the list, inserts the pop-up element into another list, and returns it, if no element in the list blocks the list until it waits for a timeout or discovers that the element can be ejected. |
| 4 |
LINDEX Key Index Get the elements in a list by index |
| 5 |
Linsert Key before| After pivot value Insert an element before or after the element in the list |
| 6 |
Llen Key Get list length |
| 7 |
Lpop Key Move out and get the first element of a list |
| 8 |
Lpush key value1 [value2] Insert one or more values into the list header |
| 9 |
Lpushx Key value Inserts one or more values into the list header that already exists |
| 10 |
Lrange Key Start stop Gets the element within the specified range of the list |
| 11 |
Lrem Key Count value Remove a list element |
| 12 |
LSET Key index value To set the value of a list element by index |
| 13 |
LTRIM Key Start stop Trim (Trim) a list, which means that the list retains only the elements within the specified interval, and the elements that are not within the specified range are deleted. |
| 14 |
Rpop Key Remove and get the last element of the list |
| 15 |
Rpoplpush Source Destination Removes the last element of the list and adds the element to another list and returns |
| 16 |
Rpush key value1 [value2] Add one or more values to the list |
| 17 |
Rpushx Key value Add a value to a list that already exists |
Redis lists (list)