Redis SUNIONSTORE命令

Redis SUNIONSTORE命令被用来存储,该组由所有的给定集合的并集所得的成员。不存在键被认为是空集。

返回值

返回整数,所得集合元素的数量。

语法

redis SUNIONSTORE命令的基本语法如下所示:

redis 127.0.0.1:6379> SUNIONSTORE DESTINATION KEY KEY1..KEYN

实例

redis 127.0.0.1:6379> SADD myset1 "hello"
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "world"
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "bar"
(integer) 1
redis 127.0.0.1:6379> SADD myset2 "hello"
(integer) 1
redis 127.0.0.1:6379> SADD myset2 "bar"
(integer) 1
redis 127.0.0.1:6379> SUNIONSTORE myset myset1 myset2
(integer) 1
redis 127.0.0.1:6379> SMEMBERS myset
1) "bar"
2) "world"
3) "hello"
4) "foo"

上一篇: 下一篇: Redis环境安装配置