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
- 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
- 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 moves out and gets the first element of the list, and if no element of the list blocks 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 popup element into another list, and returns it, if no element of the list blocks the list until the wait time-out or the popup element is found. |
4 |
LINDEX key index Gets the elements in the list by index |
5 |
Linsert Key before| After pivot value inserts an element before or after the element in the list |
6 |
Llen Key Get list length |
7 |
Lpop key moves out and gets the first element of the list |
8 |
Lpush key value1 [value2] inserts 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 list of elements in the specified range |
11 |
Lrem Key Count value Remove list element |
12 |
LSET Key index value sets the values of the list elements by index |
13 |
LTRIM key start stop trims a list (trim), 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 to 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] adds one or more values to the list |
17 |
Rpushx key value adds a value to a list that already exists |
Redis lists (list)