redis数据类型-集合类型

 

SADD: 向集合中添加元素:
192.168.2.120:6379> SADD jihe1 a b c
(integer) 3
192.168.2.120:6379> SADD jihe2 b c d
(integer) 3

查看集合的成员:
192.168.2.120:6379> SMEMBERS jihe1
1) "b"
2) "a"
3) "c"
192.168.2.120:6379> SMEMBERS jihe2
1) "b"
2) "d"
3) "c"

判断集合元素是否存在:
192.168.2.120:6379> SISMEMBER jihe1 a        #判断a 是否在集合jihe1中,在返回1,不在返回0
(integer) 1
192.168.2.120:6379> SISMEMBER jihe1 f
(integer) 0

集合的运算:
集合的差集SDIFF:
192.168.2.120:6379> SMEMBERS jihe1
1) "b"
2) "a"
3) "c"
192.168.2.120:6379> SMEMBERS jihe2
1) "b"
2) "d"
3) "c"
192.168.2.120:6379> SDIFF jihe1 jihe2
1) "a"
192.168.2.120:6379> SDIFF jihe2 jihe1
1) "d"

集合交集SINTER:
192.168.2.120:6379> SMEMBERS jihe1
1) "b"
2) "a"
3) "c"
192.168.2.120:6379> SMEMBERS jihe2
1) "b"
2) "d"
3) "c"
192.168.2.120:6379> SINTER jihe1 jihe2
1) "b"
2) "c"

集合并集SUNION:
192.168.2.120:6379> SMEMBERS jihe1
1) "b"
2) "a"
3) "c"
192.168.2.120:6379> SMEMBERS jihe2
1) "b"
2) "d"
3) "c"
192.168.2.120:6379> SUNION jihe1 jihe2
1) "a"
2) "b"
3) "d"
4) "c"







分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS