📜  Redis列表

📅  最后修改于: 2020-12-02 01:05:38             🧑  作者: Mango

Redis列表

Redis列表可以定义为字符串列表,按插入顺序排序。您可以在Redis列表的顶部或底部添加元素。

一个列表可以包含超过40亿个元素。

redis 127.0.0.1:6379> LPUSH javatpoint sql
(integer) 1
redis 127.0.0.1:6379> LPUSH javatpoint mysql
(integer) 2
redis 127.0.0.1:6379> LPUSH javatpoint cassandra
(integer) 3
redis 127.0.0.1:6379> LRANGE javatpoint 0 10
1) "cassandra"
2) "mysql"
3) "sql"
redis 127.0.0.1:6379>

Redis列出命令

Index Command Description
1 BLPOP key1 [key2 ] timeout It is used to remove and get the first element in a list, or blocks until one is available.
2 BRPOP key1 [key2 ] timeout It is used to remove and get the last element in a list, or blocks until one is available.
3 BRPOPLPUSH source destination timeout It is used to pop a value from a list, pushes it to another list and returns it; or blocks until one is available.
4 LINDEX key index It is used to get an element from a list by its index.
5 LINSERT key before|after pivot value It is used to insert an element before or after another element in a list.
6 LLEN key It is used to get the length of a list.
7 LPOP key It is used to remove and get the first element in a list.
8 LPUSH key value1 [value2] It is used to prepend one or multiple values to a list.
9 LPUSHX key value It is used to prepend a value to a list, only if the list exists.
10 LRANGE key start stop It is used to get a range of elements from a list.
11 LREM key count value It is used to remove elements from a list.
12 LSET key index value It is used to set the value of an element in a list by its index.
13 LTRIM key start stop It is used to trim a list to the specified range.
14 RPOP key It is used to remove and get the last element in a list.
15 RPOPLPUSH source destination It is used to remove the last element in a list, append it to another list and returns it.
16 RPUSH key value1 [value2] It is used to append one or multiple values to a list.
17 RPUSHX key value It is used to append a value to a list, only if the list exists.