Redis List
A Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head (left) or tail (right) of the list
A list can contain up to 2^32 - 1 elements (4294967295, over 4 billion elements per list).
Example
redis 127.0.0.1:6379> LPUSH runoobkey redis
(integer) 1
redis 127.0.0.1:6379> LPUSH runoobkey mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH runoobkey mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE runoobkey 0 10
1) "mysql"
2) "mongodb"
3) "redis"
In the example above we used LPUSH to insert three values into the list named runoobkey .
Redis List Commands
The table below lists the basic commands related to lists:
| No. | Command and Description |
|---|---|
| 1 | BLPOP key1 [key2 ] timeout |
| Remove and get the first element of the list; if the list has no elements, block the list until a timeout is reached or an element becomes available. | |
| 2 | BRPOP key1 [key2 ] timeout |
| Remove and get the last element of the list; if the list has no elements, block the list until a timeout is reached or an element becomes available. | |
| 3 | BRPOPLPUSH source destination timeout |
| Pop a value from a list, insert the popped element into another list and return it; if the list has no elements, block the list until a timeout is reached or an element becomes available. | |
| 4 | LINDEX key index |
| Get an element from the list by index | |
| 5 | LINSERT key BEFORE|AFTER pivot value |
| Insert an element before or after another element in the list | |
| 6 | LLEN key |
| Get the length of the list | |
| 7 | LPOP key |
| Remove and get the first element of the list | |
| 8 | LPUSH key value1 [value2] |
| Insert one or more values at the head of the list | |
| 9 | LPUSHX key value |
| Insert a value at the head of an existing list | |
| 10 | LRANGE key start stop |
| Get the elements of the list within a specified range | |
| 11 | LREM key count value |
| Remove list elements | |
| 12 | LSET key index value |
| Set the value of a list element by index | |
| 13 | LTRIM key start stop |
| Trim a list so that it keeps only the elements within a specified range; all elements outside the range are removed. | |
| 14 | RPOP key |
| Remove the last element of the list; the return value is the removed element. | |
| 15 | RPOPLPUSH source destination |
| Remove the last element of the list, append it to another list and return it | |
| 16 | RPUSH key value1 [value2] |
| Add one or more values to the tail of the list | |
| 17 | RPUSHX key value |
| Add a value to an existing list |