Redis 常用命令学四:集合类型命令
1.增加和删除命令
127.0.0.1:6379> SADD st a
(integer) 1
127.0.0.1:6379> SADD st r f g
(integer) 3
127.0.0.1:6379> SREM a r
(integer) 0
127.0.0.1:6379> SREM st a r
(integer) 2
2.验证元素是否在集合中
127.0.0.1:6379> SISMEMBER st a
(integer) 0
127.0.0.1:6379> SISMEMBER st b
(integer) 1
3.获取集合中的所有元素
127.0.0.1:6379> SMEMBERS st
1) "g"
2) "d"
3) "f"
4) "c"
5) "b"
4.集合的差集、并集、交集
127.0.0.1:6379> SDIFF sr st
1) "a"
127.0.0.1:6379> SUNION sr st
1) "g"
2) "d"
3) "f"
4) "c"
5) "a"
6) "b"
127.0.0.1:6379> SINTER sr st
1) "c"
2) "d"
3) "b"
5.求集合中元素的个数
127.0.0.1:6379> SCARD st
(integer) 5
6.从集合中随机弹出一个元素
127.0.0.1:6379> SPOP st
"b"