Redis Lists
# Redis Lists
Redis lists are simple string lists, sorted in insertion order. You can add an element to the head (left) or tail (right) of a list.
A list can contain a maximum of 2^32 - 1 elements (4,294,967,295, over 4 billion elements per list).
### Example
redis 127.0.0.1:6379> LPUSH tutorialkey redis
(integer) 1
redis 127.0.0.1:6379> LPUSH tutorialkey mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH tutorialkey mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE tutorialkey 0 10
1) "mysql"
2) "mongodb"
3) "redis"
In the above example, we used **LPUSH** to insert three values into a list named **tutorialkey**.
### Redis List Commands
The following table lists the basic commands related to lists:
| No. | Command & Description |
| --- | --- |
| 1 | [BLPOP key1 timeout](#) Removes and returns the first element of the list, or blocks the list until an element is available or the timeout is reached. |
| 2 | [BRPOP key1 timeout](#) Removes and returns the last element of the list, or blocks the list until an element is available or the timeout is reached. |
| 3 | (#) Pops a value from a list, pushes it to another list, and returns it; or blocks the list until an element is available or the timeout is reached. |
| 4 | (#) Gets an element from a list by its index. |
| 5 | [LINSERT key BEFORE|AFTER pivot value](#) Inserts an element before or after another element in a list. |
| 6 | (#) Gets the length of a list. |
| 7 | (#) Removes and returns the first element of the list. |
| 8 | [LPUSH key value1 ](#) Inserts one or more values at the head of the list. |
| 9 | (#) Inserts a value at the head of the list only if the list already exists. |
| 10 | (#) Gets a range of elements from a list. |
| 11 | (#) Removes elements from a list. |
| 12 | (#) Sets the value of an element in a list by its index. |
| 13 | (#) Trims an existing list so that it will contain only the specified range of elements. |
| 14 | (#) Removes and returns the last element of the list. |
| 15 | (#) Removes the last element of the source list, pushes it to the destination list, and returns it. |
| 16 | [RPUSH key value1 ](#) Appends one or more values to the tail of the list. |
| 17 | (#) Appends a value to the tail of the list only if the list already exists. |
YouTip