set 操作
添加 sadd myset 1 2 3 4 5 6 7 8 9 0 1
取数据 smembers myset
127.0.0.1:6379> sadd myset 1 2 3 4 5 6 7 8 9 0 1
(integer) 10
127.0.0.1:6379> smembers myset
1) "0"
2) "1"
3) "2"
4) "3"
5) "4"
6) "5"
7) "6"
8) "7"
9) "8"
取长度
scard myset

取差集
sdiff one two
127.0.0.1:6379> sadd one a b c
(integer) 3
127.0.0.1:6379> sadd two b c d
(integer) 3
127.0.0.1:6379> sdiff one two
1) "a"

取差集并且放新的set里面
127.0.0.1:6379> sdiffstore newset one two
(integer) 1
127.0.0.1:6379> smembers newset
1) "a"

取交集
127.0.0.1:6379> sinter one two
1) "b"
2) "c"
127.0.0.1:6379>

取交际放入新的集合
127.0.0.1:6379> sinterstore newset one two
(integer) 2

判断a是不是在one中
127.0.0.1:6379> sismember one a
(integer) 1

把a 从one 移动的two
127.0.0.1:6379> smove one two a
(integer) 1

随机取出一个
127.0.0.1:6379> srandmember two 1
1) "c"

把指定元素从某个集合移除
127.0.0.1:6379> srem one 0
(integer) 1

取并集(如果有重复,会去除)
127.0.0.1:6379> sunion two one
1) "5"
2) "g"
3) "3"
4) "c"
5) "9"
6) "8"
7) "0"
8) "1"
9) "f"
10) "e"
11) "4"
12) "2"
13) "a"
14) "b"
15) "h"
16) "7"
17) "d"
18) "6"

取并集放入新的集合
127.0.0.1:6379> sunionstore new ont two
(integer) 18