Redis 基础教程

Redis 命令

Redis 高级教程

Redis 笔记

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

Redis SDIFFSTORE 命令

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


SDIFFSTORE 命令类似于 SDIFF,不同之处在于该命令不返回结果集,而是将结果存放在 destination 集合中。如果 destination 已经存在,则将其覆盖重写。

命令格式

SDIFFSTORE destination key [key ...]

可用版本:>=1.0.0

时间复杂度:O(N),N 为指定集合的所有元素个数。

命令返回值

返回结果集的列表。

示例

redis> SADD key1 a b c d
(integer) 4
redis> SADD key2 c
(integer) 1
redis> SADD key3 a c e
(integer) 3
redis> SDIFFSTORE dest key1 key2 key3
(integer) 2
redis> SMEMBERS dest
1) "b"
2) "d"