English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Lists (List)

Redis lists are simple string lists, sorted in the order of insertion. You can add an element to the head (left) or tail (right) of the list

A list can contain up to 232 - 1 elements (4294967295, each list over40 billion elements).

Online examples

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

In the above examples, we used LPUSH Insert three values into the list named w3codeboxkey in the list.

Redis List Commands

The following table lists the basic commands related to the list:

Serial numberCommand and description
1BLPOP key1 [key2 ] timeout
Remove and get the first element of the list, if the list has no elements, it will block the list until the timeout is reached or an element is popped.
2BRPOP key1 [key2 ] timeout
Remove and get the last element of the list, if the list has no elements, it will block the list until the timeout is reached or an element is popped.
3BRPOPLPUSH 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, it will block the list until the timeout is reached or an element is popped.
4LINDEX key index
Get elements from a list by index
5LINSERT key BEFORE|AFTER pivot value
Insert an element before or after an element in the list
6LLEN key
Get the length of the list
7LPOP key
Remove and get the first element of the list
8LPUSH key value1 [value2]
Insert one or more values at the beginning of a list
9LPUSHX key value
Insert a value at the beginning of an existing list
10LRANGE key start stop
Get elements within a specified range of the list
11LREM key count value
Remove list elements
12LSET key index value
Set the value of a list element by index
13LTRIM key start stop
Trim a list (trim), that is, keep only the elements within the specified range in the list, and delete the elements outside the specified range.
14RPOP key
Remove the last element of the list, return the value of the removed element.
15RPOPLPUSH source destination
Remove the last element of the list, add it to another list and return
16RPUSH key value1 [value2]
Add one or more values to a list
17RPUSHX key value
Add values to an existing list