set中的值是不能重复的,无序
# 向集合中添加元素
127.0.0.1:6379> SADD myset hello world nihao hey
(integer) 4
# 查询集合中的成员
127.0.0.1:6379> SMEMBERS myset
1) "hey"
2) "nihao"
3) "world"
4) "hello"
#获取set集合中成员个数
127.0.0.1:6379> SCARD myset
(integer) 4
#移除set成员中的指定元素
127.0.0.1:6379> SREM myset hey
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "nihao"
2) "world"
3) "hello"
#从set集合中随机抽选出一个元素
127.0.0.1:6379> SRANDMEMBER myset
"hey"
127.0.0.1:6379> SRANDMEMBER myset
"hello"
#随机删除一个元素
127.0.0.1:6379> SPOP myset
"hey"
127.0.0.1:6379> SPOP myset
"nihao"
127.0.0.1:6379> SPOP myset
"hello"
127.0.0.1:6379> SMEMBERS myset
1) "world"
#set中数字集合类
127.0.0.1:6379> SMEMBERS myset
1) "hey"
2) "hi"
3) "hello"
4) "world"
127.0.0.1:6379> SADD myset2 name age hey hi
(integer) 4
# 差集
127.0.0.1:6379> SDIFF myset myset2
1) "world"
2) "hello"
#交集
127.0.0.1:6379> SINTER myset myset2
1) "hey"
2) "hi"
# 并集
127.0.0.1:6379> SUNION myset myset2
1) "name"
2) "world"
3) "age"
4) "hey"
5) "hi"
6) "hello"