set中的值无序不能重复!!!
SADD 添加元素
SMEMBERS 查询元素
127.0.0.1:6379> SADD set one two three (integer) 3 127.0.0.1:6379> SMEMBERS set 1) "three" 2) "two" 3) "one"
SISMEMBER 查看是否存在这个元素
127.0.0.1:6379> SMEMBERS set 1) "three" 2) "two" 3) "one" 127.0.0.1:6379> SISMEMBER set one (integer) 1 127.0.0.1:6379> SISMEMBER set four (integer) 0
SCARD 获取元素的个数
127.0.0.1:6379> SCARD set (integer) 3
SMEMBERS移除指定元素,可以移除多个,用空格分隔
127.0.0.1:6379> SREM set two (integer) 1 127.0.0.1:6379> SMEMBERS set 1) "three" 2) "one"
SRANDMEMBER随机抽选出指定个数的个数
127.0.0.1:6379> SMEMBERS set 1) "three" 2) "two" 3) "one" 4) "four" 5) "five" 127.0.0.1:6379> SRANDMEMBER set 2 1) "one" 2) "four"
SREM删除指定的一个或多个元素
127.0.0.1:6379> SREM set1 ok (integer) 1 127.0.0.1:6379> SMEMBERS set1 1) "two" 127.0.0.1:6379> FLUSHALL OK 127.0.0.1:6379> sadd set one two three four (integer) 4 127.0.0.1:6379> SREM set two three (integer) 2 127.0.0.1:6379> SMEMBERS set 1) "one" 2) "four"
随机删除一个或指定个数的元素
127.0.0.1:6379> SMEMBERS set 1) "three" 2) "two" 3) "one" 4) "four" 5) "five" 127.0.0.1:6379> SPOP set "three" 127.0.0.1:6379> SPOP set 2 1) "one" 2) "four"
SMOVE移动某个元素到另一个set中,语法:SMOVE 源set 目的set 元素
127.0.0.1:6379> SADD set one two four (integer) 3 127.0.0.1:6379> SADD set1 ok (integer) 1 127.0.0.1:6379> SMOVE set set1 two (integer) 1 127.0.0.1:6379> SMEMBERS set 1) "one" 2) "four" 127.0.0.1:6379> SMEMBERS set1 1) "two" 2) "ok"
SDIFF一个set集合和另一个set集合的差集
127.0.0.1:6379> SADD s1 a1 a2 a3(integer) 3127.0.0.1:6379> SADD s2 a2 a3 a5 a6(integer) 4127.0.0.1:6379> SDIFF s1 s21) "a1"127.0.0.1:6379> SDIFF s2 s11) "a5"2) "a6"
SINTER一个set集合和另一个set集合的交集
127.0.0.1:6379> SINTER s1 s21) "a3"2) "a2"
SUNION一个set集合和另一个set集合的并集
127.0.0.1:6379> SUNION s1 s21) "a5"2) "a3"3) "a6"4) "a2"5) "a1"
学习参考狂神说java