📅  最后修改于: 2020-11-26 07:03:04             🧑  作者: Mango
Redis列表只是字符串列表,按插入顺序排序。您可以在Redis列表的顶部或底部添加元素。
列表的最大长度为2个32 – 1元件(4294967295,超过4十亿每列表中的元素)。
redis 127.0.0.1:6379> LPUSH tutorials redis
(integer) 1
redis 127.0.0.1:6379> LPUSH tutorials mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH tutorials mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE tutorials 0 10
1) "mysql"
2) "mongodb"
3) "redis"
在上面的示例中,通过命令LPUSH将三个值插入到名为“ tutorials”的Redis列表中。
下表列出了一些与列表相关的基本命令。
Sr.No | Command & Description |
---|---|
1 | BLPOP key1 [key2 ] timeout
Removes and gets the first element in a list, or blocks until one is available |
2 | BRPOP key1 [key2 ] timeout
Removes and gets the last element in a list, or blocks until one is available |
3 | BRPOPLPUSH source destination timeout
Pops a value from a list, pushes it to another list and returns it; or blocks until one is available |
4 | LINDEX key index
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 | LLEN key
Gets the length of a list |
7 | LPOP key
Removes and gets the first element in a list |
8 | LPUSH key value1 [value2]
Prepends one or multiple values to a list |
9 | LPUSHX key value
Prepends a value to a list, only if the list exists |
10 | LRANGE key start stop
Gets a range of elements from a list |
11 | LREM key count value
Removes elements from a list |
12 | LSET key index value
Sets the value of an element in a list by its index |
13 | LTRIM key start stop
Trims a list to the specified range |
14 | RPOP key
Removes and gets the last element in a list |
15 | RPOPLPUSH source destination
Removes the last element in a list, appends it to another list and returns it |
16 | RPUSH key value1 [value2]
Appends one or multiple values to a list |
17 | RPUSHX key value
Appends a value to a list, only if the list exists |