set
list命令详解
# SADD key member [member ...] 添加一个或多个指定的member元素到集合的 key中
127.0.0.1:6379> SADD myset 'for' 'you' 'you' 'a' 'thousand' 'times' 'over'
(integer) 6
# SMEMBERS key 返回key集合所有的元素
127.0.0.1:6379> SMEMBERS myset
1) "thousand"
2) "you"
3) "for"
4) "over"
5) "a"
6) "times"
# SCARD key 返回集合元素的数量
127.0.0.1:6379> SCARD myset
(integer) 6
# SPOP key [count] 随机从集合中删除count个元素,没有count删除一个元素
127.0.0.1:6379> SPOP myset 2
1) "times"
2) "a"
127.0.0.1:6379> SMEMBERS myset
1) "over"
2) "for"
3) "you"
4) "thousand"
# SREM key member [member ...] 在key集合中移除指定的元素
127.0.0.1:6379> SREM myset 'for' 'thousand' 'y'
(integer) 2
127.0.0.1:6379> SMEMBERS myset
1) "over"
2) "you"
# SINTER key [key ...] 多个集合的交集
127.0.0.1:6379> SADD set1 1 2 3 4 5
(integer) 5
127.0.0.1:6379> SADD set2 5 1 2 9 0
(integer) 5
127.0.0.1:6379> SINTER set1 set2
1) "1"
2) "2"
3) "5"
# SUNION key [key ...] 多个集合的并集
127.0.0.1:6379> SUNION set1 set2
1) "0"
2) "1"
3) "2"
4) "3"
5) "4"
6) "5"
7) "9"
# SDIFF key [key ...] 多个集合的的差集的元素
127.0.0.1:6379> SDIFF set1 set2
1) "3"
2) "4"
# SDIFFSTORE destination key [key ...] 返回多个集合的的差集的元素,并存储在新的集合destination中
127.0.0.1:6379> SDIFFSTORE set1_2 set1 set2
(integer) 2
127.0.0.1:6379> SMEMBERS set1_2
1) "3"
2) "4"
# SINTERSTORE destination key [key ...] 多个集合的的交集存储在新的集合destination中
# SUNIONSTORE destination key [key ...] 多个集合的的并集存储在新的集合destination中