Latest web development tutorials

Redis list (List)

Redis list is a simple list of strings sorted insertion order. You can add a list of guide element head (left) or rear (on the right)

A list can contain up 232--1 element (4,294,967,295 over 4 billion each list element).

Examples

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

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

In the example above we usedLPUSH three values into a list of named among w3bigkey.

Redis command list

The following table shows a list of related basic commands:

No. Command and description
1 BLPOP key1 [key2] timeout
And get out of the first element of the list, if the list is not a list of the elements will be blocked until a timeout or a date can be found in the pop-up element.
2 BRPOP key1 [key2] timeout
And get out of the last element of the list, if the list is not a list of the elements will be blocked until a timeout or a date can be found in the pop-up element.
3 BRPOPLPUSH source destination timeout
Pop a value from the list, the pop element into another list and return it; if there is no element of the list will block until a timeout or until the list can be found in the pop-up element.
4 LINDEX key index
Get a list of the elements by index
5 LINSERT key BEFORE | AFTER pivot value
In the list of elements before or after the insert elements
6 LLEN key
Get a list of length
7 LPOP key
And get out of the first element of the list
8 LPUSH key value1 [value2]
One or more values ​​into the head of the list
9 LPUSHX key value
One or more values ​​into an existing list head
10 LRANGE key start stop
Get a list of the elements in the specified range
11 LREM key count value
Remove list element
12 LSET key index value
Set the value of elements of the list by index
13 LTRIM key start stop
For a list of trim (trim), that is, make a list of only the retention interval specified element, the element is not specified within the range will be deleted.
14 RPOP key
Remove and obtain a list of the last element
15 RPOPLPUSH source destination
Removes the last element of the list, and adds the element to another list and return
16 RPUSH key value1 [value2]
Add one or more values ​​in the list
17 RPUSHX key value
Add value to the existing list