时间:2021-10-30 10:33:03 | 栏目:Redis | 点击:次
一、sinter 、sunion 、sdiff
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"
redis> SMEMBERS songs 1) "Billie Jean" redis> SMEMBERS my_songs 1) "Believe Me" redis> SUNION songs my_songs # 取的是集合的并集数据据 1) "Billie Jean" 2) "Believe Me"
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"
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"
redis> SMEMBERS NoSQL 1) "MongoDB" 2) "Redis" redis> SMEMBERS SQL 1) "sqlite" 2) "MySQL" redis> SUNIONSTORE db NoSQL SQL # 将并集的数据存储到 db 对象中 (integer) 4 redis> SMEMBERS db # 查看 db 对象中的 所有数据 1) "MySQL" 2) "sqlite" 3) "MongoDB" 4) "Redis"
redis> SMEMBERS joe_movies 1) "hi, lady" 2) "Fast Five" 3) "2012" redis> SMEMBERS peter_movies 1) "bet man" 2) "start war" 3) "2012" redis> SDIFFSTORE joe_diff_peter joe_movies peter_movies # 将差集的数据存储到 joe_diff_peter 对象中 (integer) 2 redis> SMEMBERS joe_diff_peter # 查看 joe_diff_peter 对象中的 所有数据 1) "hi, lady" 2) "Fast Five"