Easy Tutorial
❮ Transactions Discard Server Client Setname ❯

Redis List

Redis Lists are simply lists of strings, sorted by insertion order. You can add an element to the head (left) or the tail (right) of the list.

A list can contain up to 2^32 - 1 elements (4,294,967,295, more than 4 billion elements per list).

Example

redis 127.0.0.1:6379> LPUSH tutorialprokey redis
(integer) 1
redis 127.0.0.1:6379> LPUSH tutorialprokey mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH tutorialprokey mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE tutorialprokey 0 10

1) "mysql"
2) "mongodb"
3) "redis"

In the above example, we used LPUSH to insert three values into the list named tutorialprokey.

Redis List Commands

The table below lists the basic commands related to lists:

No. Command and Description
1 BLPOP key1 [key2 ] timeout <br>Remove and get the first element in a list, or block until one is available.
2 BRPOP key1 [key2 ] timeout <br>Remove and get the last element in a list, or block until one is available.
3 BRPOPLPUSH source destination timeout <br>Pop a value from a list, push it to another list and return it; or block until one is available.
4 LINDEX key index <br>Get an element from a list by its index.
5 LINSERT key BEFORE|AFTER pivot value <br>Insert an element before or after another element in a list.
6 LLEN key <br>Get the length of a list.
7 LPOP key <br>Remove and get the first element in a list.
8 LPUSH key value1 [value2] <br>Prepend one or multiple values to a list.
9 LPUSHX key value <br>Prepend a value to a list, only if the list exists.
10 LRANGE key start stop <br>Get a range of elements from a list.
11 LREM key count value <br>Remove elements from a list.
12 LSET key index value <br>Set the value of an element in a list by its index.
13 LTRIM key start stop <br>Trim a list to the specified range.
14 RPOP key <br>Remove and get the last element in a list.
15 RPOPLPUSH source destination <br>Remove the last element in a list, append it to another list and return it.
16 RPUSH key value1 [value2] <br>Append one or multiple values to a list.
17 RPUSHX key value <br>Append a value to a list, only if the list exists.
❮ Transactions Discard Server Client Setname ❯