Redis SUNIONSTORE命令用于对多个集合进行合并,并将结果存储到一个新的集合中.
SUNIONSTORE new_set key1 [key2...]
其中:
new_set:存储合并后结果的新集合
12⑦0.0.1:6379> SADD set1 a b c d
(integer) 4
12⑦0.0.1:6379> SADD set2 c d e f
(integer) 4
12⑦0.0.1:6379> SADD set3 a e f g
(integer) 4
现在执行如下命令:
12⑦0.0.1:6379> SUNIONSTORE new_set set1 set2 set3
(integer) 7
12⑦0.0.1:6379> SADD set1 a b c d
(integer) 4
12⑦0.0.1:6379> SADD set2 b c d e
(integer) 4
12⑦0.0.1:6379> SUNIONSTORE new_set set1 set2
(integer) 5
新集合中不会包含重复的元素,即合并后的集合中每个元素只会出现一次.
如果要合并的集合不存在,则新集合也不存在,该命令什么也不会做.
以上就是土嘎嘎小编为大家整理的Redis SUNIONSTORE命令相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!