SDIFFSTORE destination key [key …]

可用版本: >= 1.0.0
时间复杂度: O(N), N 是所有给定集合的成员数量之和。

这个命令的作用和 SDIFF key [key …] 类似,但它将结果保存到 destination 集合,而不是简单地返回结果集。

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

destination 可以是 key 本身。

返回值

结果集中的元素数量。

代码示例

  1. redis> SMEMBERS joe's_movies
  2. 1) "hi, lady"
  3. 2) "Fast Five"
  4. 3) "2012"
  5.  
  6. redis> SMEMBERS peter's_movies
  7. 1) "bet man"
  8. 2) "start war"
  9. 3) "2012"
  10.  
  11. redis> SDIFFSTORE joe_diff_peter joe's_movies peter's_movies
  12. (integer) 2
  13.  
  14. redis> SMEMBERS joe_diff_peter
  15. 1) "hi, lady"
  16. 2) "Fast Five"