SUNIONSTORE

将多个集合的并集存储在一个键中。

语法

SUNIONSTORE destination key [key ...]

引入版本:1.0.0

复杂度摘要:O(N)

[!NOTE] 此命令的行为在集群 Redis 环境中有所不同。请参阅 多键操作 页面了解更多信息。

该命令等于 SUNION,但不返回结果集,而是存储在 destination 中。

如果 destination 已存在,则将其覆盖。

必需参数

destination

存储结果集的键。

key [key ...]

一个或多个设置键进行联合。

示例

redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SUNIONSTORE key key1 key2
(integer) 5
redis> SMEMBERS key
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"

Redis Software 与 Redis Cloud 兼容性

Redis
软件
Redis
Cloud
说明
✅ 标准
✅ 主动-主动
✅ 标准
✅ 主动-主动

返回值

RESP2

整数回复:结果集中的元素数量。

RESP3

整数回复:结果集中的元素数量。

参见

SUNION | SUNIONCARD

资料来源:Redis 官方 SUNIONSTORE 文档;中文内容参考 Redis 文档许可。