📜  Redis集

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

Redis集

Redis集是唯一字符串的无序集合。唯一字符串表示集合中没有重复的单个字符串。

在Redis集合中,添加,删除和测试O(1)中成员的存在(恒定时间,无论Set中包含的元素数量如何)。每个列表的最大长度超过40亿个元素。

redis 127.0.0.1:6379> SADD javatpoint db2
(integer) 1
redis 127.0.0.1:6379> SADD javatpoint mongodb
(integer) 1
redis 127.0.0.1:6379> SADD javatpoint db2
(integer) 0
redis 127.0.0.1:6379> SADD javatpoint cassandra
(integer) 1
redis 127.0.0.1:6379> SMEMBERS javatpoint
1) "cassandra"
2) "db2"
3) "mongodb"

在上面的示例中,您可以看到我们使用SADD命令在集合中添加了4个元素。但是,使用SMEMBERS命令只能检索3个元素,因为一个元素是重复元素,并且Redis集只能读取一次重复值。

Redis设置命令

Index Command Description
1 SADD key member1 [member2] It is used to add one or more members to a set.
2 SCARD key It is used to getsthe number of members in a set.
3 SDIFF key1 [key2] It is used to subtract multiple sets.
4 SDIFFstore destination key1 [key2] It is used to subtract multiple sets and stores the resulting set in a key.
5 SINTER key1 [key2] It is used to intersect multiple sets.
6 SINTERSTORE destination key1 [key2] It is used to intersect multiple sets and stores the resulting set in a key.
7 SISMEMBER key member It is used to determine if a given value is a member of a set.
8 SMOVE source destination member It is used to move a member from one set to another.
9 SPOP key It is used to remove and returns a random member from a set.
10 SRANDMEMBER key [count] It is used to get one or multiple random members from a set.
11 SREM key member1 [member2] It is used to remove one or more members from a set.
12 SUNION key1 [key2] It is used to add multiple sets.
13 SUNIONSTORE destination key1 [key2] It is used to add multiple sets and stores the resulting set in a key.
14 SSCAN key cursor [match pattern] [count count] It is used to incrementally iterates set elements.