English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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).
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.
The following table lists the basic commands related to the list:
Serial number | Command and description |
---|---|
1 | BLPOP 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. |
2 | BRPOP 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. |
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, it will block the list until the timeout is reached or an element is popped. |
4 | LINDEX key index Get elements from a list by index |
5 | LINSERT key BEFORE|AFTER pivot value Insert an element before or after an 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 beginning of a list |
9 | LPUSHX key value Insert a value at the beginning of an existing list |
10 | LRANGE key start stop Get elements within a specified range of the list |
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 (trim), that is, keep only the elements within the specified range in the list, and delete the elements outside the specified range. |
14 | RPOP key Remove the last element of the list, return the value of the removed element. |
15 | RPOPLPUSH source destination Remove the last element of the list, add it to another list and return |
16 | RPUSH key value1 [value2] Add one or more values to a list |
17 | RPUSHX key value Add values to an existing list |