https://blog.csdn.net/xiaojin21cen/article/details/88602153

一、sinter 、sunion 、sdiff

redis 支持 Set集合的数据存储,其中有三个比较特殊的方法:

1.1、sinter 交集的示例

redis> SMEMBERS group_1
1) "LI LEI"
2) "TOM"
3) "JACK"

redis> SMEMBERS group_2
1) "HAN MEIMEI"
2) "JACK"

redis> SINTER group_1 group_2      # 取的是交集的数据
1) "JACK"

1.2、sunion 并集的示例

redis> SMEMBERS songs
1) "Billie Jean"

redis> SMEMBERS my_songs
1) "Believe Me"

redis> SUNION songs my_songs       # 取的是集合的并集数据
1) "Billie Jean"
2) "Believe Me"

1.3、sdiff 差集的示例

redis> SMEMBERS peter_movies
1) "bet man"
2) "start war"
3) "2012"

redis> SMEMBERS joe_movies
1) "hi, lady"
2) "Fast Five"
3) "2012"

redis> SDIFF peter_movies joe_movies     # 取的是两个集合的差集
1) "bet man"
2) "start war"

二、sinterstore、sunionstore、sdiffstore

2.1、sinterstore 交集的示例

redis> SMEMBERS songs
1) "good bye joe"
2) "hello,peter"

redis> SMEMBERS my_songs
1) "good bye joe"
2) "falling"

redis> SINTERSTORE song_interset songs my_songs           # 将交集的数据存储到 song_interset 对象中
(integer) 1

redis> SMEMBERS song_interset                 # 查看 song_interset 对象中的 所有数据
1) "good bye joe"

2.2、sunionstore 并集的示例