sadd:添加集合元素
127.0.0.1:6379> sadd runnoobkey redis mongodb mysql
(integer) 3
scard:查看集合数量
127.0.0.1:6379> SCARD runnoobkey
(integer) 3
sdiff:集合左交差集
127.0.0.1:6379> sadd key1 'a' 'c' 'b'
(integer) 3
127.0.0.1:6379> sadd key1 'd' 'f' 'j'
(integer) 3
127.0.0.1:6379> SADD key2 'a' 'b' 'n'
(integer) 3
127.0.0.1:6379> SDIFF key1 key2
1) "c"
2) "f"
3) "j"
4) "d"
Sdiffstore: 命令将给定集合之间的差集存储在指定的集合中。如果指定的集合 key 已存在,则会被覆盖。
127.0.0.1:6379> sadd name 'liyi' 'lier' 'lisan'
(integer) 3
127.0.0.1:6379> sadd name1 'liyi' 'wangyi'
(integer) 2
127.0.0.1:6379> SDIFFSTORE name name1
(integer) 2
Sinter :命令返回给定所有给定集合的交集。 不存在的集合 key 被视为空集。 当给定集合当中有一个空集时,结果也为空集(根据集合运算定律)
127.0.0.1:6379> SMEMBERS name1
1) "liyi"
2) "wangyi"
127.0.0.1:6379> SMEMBERS name
1) "wangwu"
2) "liyi"
3) "wangyi"
127.0.0.1:6379> sinter name name1
1) "liyi"
2) "wangyi"
Smembers:返回集合中的所有成员
127.0.0.1:6379> SMEMBERS name1
1) "liyi"
2) "wangyi"
127.0.0.1:6379> SMEMBERS name
1) "wangwu"
2) "liyi"
3) "wangyi"
sismember: 命令判断成员元素是否是集合的成员
127.0.0.1:6379> SMEMBERS name
1) "wangwu"
2) "liyi"
3) "wangyi"
127.0.0.1:6379> SISMEMBER name liyi
(integer) 1
127.0.0.1:6379> SISMEMBER name wangwang
(integer) 0
127.0.0.1:6379>
Sinterstore:返回给定所有集合的交集并存储在 destination 中
127.0.0.1:6379> SINTERSTORE key3 name name1
(integer) 2
127.0.0.1:6379> SMEMBERS key3
1) "liyi"
2) "wangyi"
Smove :命令将指定成员 wangwu元素从 name集合移动到 name1集合
127.0.0.1:6379> SMEMBERS name1
1) "liyi"
2) "wangyi"
127.0.0.1:6379> SMEMBERS name
1) "wangwu"
2) "liyi"
127.0.0.1:6379> smove name name1 "wangwu"
(integer) 1
127.0.0.1:6379> SMEMBERS name1
1) "wangwu"
2) "liyi"
3) "wangyi"
127.0.0.1:6379> SMEMBERS name
1) "liyi"
Spop:移除并返回集合中的一个随机元素
127.0.0.1:6379> SMEMBERS name1
1) "wangwu"
2) "liyi"
3) "wangyi"
127.0.0.1:6379> spop name1
"liyi"
127.0.0.1:6379> SMEMBERS name1
1) "wangwu"
2) "wangyi"
127.0.0.1:6379>
Srandmember :命令用于返回集合中的一个随机元素。
127.0.0.1:6379> SRANDMEMBER name1 2
1) "wangwu"
2) "wangyi"
127.0.0.1:6379> SRANDMEMBER name1 1
1) "wangyi"
Srem:移除集合中一个或多个成员
127.0.0.1:6379> SMEMBERS name1
1) "wangwu"
2) "wangyi"
127.0.0.1:6379> SREM name1 'wangwu' 'wangyi'
(integer) 2
127.0.0.1:6379> SMEMBERS name1
(empty list or set)
127.0.0.1:6379>
Sunion:返回所有给定集合的并集
127.0.0.1:6379> SMEMBERS name
1) "wugangang"
2) "wuyue"
3) "liyi"
127.0.0.1:6379> sadd name1 'zhangsan' 'zhangyi'
(integer) 2
127.0.0.1:6379> SMEMBERS name1
1) "zhangsan"
2) "zhangyi"
127.0.0.1:6379> SUNION name name1
1) "zhangsan"
2) "wugangang"
3) "liyi"
4) "wuyue"
5) "zhangyi"
Sunionstore:所有给定集合的并集存储在 name2 集合中
127.0.0.1:6379> SMEMBERS name1
1) "zhangsan"
2) "zhangyi"
127.0.0.1:6379> SMEMBERS name
1) "zhangsan"
2) "ganggang"
3) "zhangyi"
127.0.0.1:6379> sunionstore name2 name1 name
(integer) 3
127.0.0.1:6379> SMEMBERS name2
1) "zhangsan"
2) "ganggang"
3) "zhangyi"
Sscan:迭代集合中的元素
127.0.0.1:6379> sscan name2 0 match z*
1) "0"
2) 1) "zhangyi"
2) "zhangsan"