常用命令
127.0.0.1:6379> sadd k1 v1 v2 v3 ## 存入一个set
(integer) 3
------------------------------
127.0.0.1:6379> smembers k1 ##按照key取出set
1) "v2"
2) "v3"
3) "v1"
127.0.0.1:6379>
--------------------------------------
127.0.0.1:6379> sismember k1 v1 ##返回set中是否存有某个元素
(integer) 1
127.0.0.1:6379> sismember k2 v6
(integer) 0
127.0.0.1:6379>
---------------------------------------
127.0.0.1:6379> scard k1 ##返回元素个数
(integer) 3
------------------------------------------------
127.0.0.1:6379> srem k1 v1 v2 ##删除set中部分元素
(integer) 2
127.0.0.1:6379> smembers k1
1) "v3"
127.0.0.1:6379>
-------------------------------------------------------------
127.0.0.1:6379> sadd k2 v1 v2 v3
(integer) 3
127.0.0.1:6379> spop k2 2 ##随机吐出set中的几个值(从原set中移除)
1) "v3"
2) "v2"
------------------------------------------------------------------------
127.0.0.1:6379> sadd k1 v1 v2 v3 v4
(integer) 4
127.0.0.1:6379> srandmember k1 3 #随机返回set中的几个值,但不删除
1) "v2"
2) "v1"
3) "v4"
127.0.0.1:6379> smembers k1
1) "v2"
2) "v3"
3) "v4"
4) "v1"
127.0.0.1:6379>
---------------------------------------------------------------
127.0.0.1:6379> sadd k2 v11 v22 v33 v44
(integer) 4
127.0.0.1:6379> smove k1 k2 v1 ##将k1 中的某个值移动到k2
(integer) 1
127.0.0.1:6379> smembers k2
1) "v33"
2) "v44"
3) "v11"
4) "v22"
5) "v1"
127.0.0.1:6379> smembers k1
1) "v2"
2) "v3"
3) "v4"
127.0.0.1:6379>
--------------------------------------------------------
127.0.0.1:6379> sadd k1 v2 v3 v4 v5
(integer) 4
127.0.0.1:6379> sadd k2 v3 v4 v5 v6 v7
(integer) 5
127.0.0.1:6379> sinter k1 k2 #取交集
1) "v5"
2) "v3"
3) "v4"
127.0.0.1:6379> sunion k1 k2 #并集
1) "v7"
2) "v5"
3) "v4"
4) "v6"
5) "v2"
6) "v3"
127.0.0.1:6379> sdiff k1 k2 #差集(k1中有的,k2中没有的)
1) "v2"