📅  最后修改于: 2020-11-26 07:03:32             🧑  作者: Mango
Redis集是唯一字符串的无序集合。唯一方法集不允许重复键中的数据。
在Redis集合中,添加,删除和测试O(1)中成员的存在(恒定时间,无论Set中包含的元素数量如何)。一个列表的最大长度为2个32 – 1元件(4294967295,超过4十亿每组元素)。
redis 127.0.0.1:6379> SADD tutorials redis
(integer) 1
redis 127.0.0.1:6379> SADD tutorials mongodb
(integer) 1
redis 127.0.0.1:6379> SADD tutorials mysql
(integer) 1
redis 127.0.0.1:6379> SADD tutorials mysql
(integer) 0
redis 127.0.0.1:6379> SMEMBERS tutorials
1) "mysql"
2) "mongodb"
3) "redis"
在上面的示例中,通过命令SADD将三个值插入名为“ tutorials”的Redis集中。
下表列出了一些与集合有关的基本命令。
Sr.No | Command & Description |
---|---|
1 | SADD key member1 [member2]
Adds one or more members to a set |
2 | SCARD key
Gets the number of members in a set |
3 | SDIFF key1 [key2]
Subtracts multiple sets |
4 | SDIFFSTORE destination key1 [key2]
Subtracts multiple sets and stores the resulting set in a key |
5 | SINTER key1 [key2]
Intersects multiple sets |
6 | SINTERSTORE destination key1 [key2]
Intersects multiple sets and stores the resulting set in a key |
7 | SISMEMBER key member
Determines if a given value is a member of a set |
8 | SMEMBERS key
Gets all the members in a set |
9 | SMOVE source destination member
Moves a member from one set to another |
10 | SPOP key
Removes and returns a random member from a set |
11 | SRANDMEMBER key [count]
Gets one or multiple random members from a set |
12 | SREM key member1 [member2]
Removes one or more members from a set |
13 | SUNION key1 [key2]
Adds multiple sets |
14 | SUNIONSTORE destination key1 [key2]
Adds multiple sets and stores the resulting set in a key |
15 | SSCAN key cursor [MATCH pattern] [COUNT count]
Incrementally iterates set elements |