Redis 基础教程

Redis 命令

Redis 高级教程

Redis 笔记

original icon
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.knowledgedict.com/tutorial/redis-command-sunionstore.html

Redis SUNIONSTORE 命令

Redis 集合(Sets) Redis 集合(Sets)


SUNIONSTORE 命令类似于 SUNION 命令,但它将结果保存到 destination 集合,而不是简单地返回结果集。如果 destination 已经存在,则将其覆盖。

命令格式

SUNIONSTORE destination key [key ...]

可用版本:>=1.0.0

时间复杂度:O(N),N 是所有给定集合的成员数量之和。

命令返回值

返回结果集中的元素数量。

示例

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