set是string类型元素的集合
成员唯一,意味着没有重复值【去重的list】
无序,排列是乱序的,与插入顺序无关
1 判断key的类型
type key

2 获取set类型的长度【成员数】
scard key

3 获取set的所有成员
smembers key
熟悉了集合运算之后,我们也可以通过sdiff,sunion,sinter来获取集合元素

4 判断一个元素是不是集合中的元素
sismember key member

5 创建集合,添加元素
sadd key member1 member2

6 删除集合中一个或者多个指定元素
srem key value1 value2

7 移除集合中的一个元素
spop key

8 随即返回集合中的一个或者多个元素
srandmember key N

9 将集合1的元素移动到集合2
smove key1 key2 membet

10
集合的交集,差集,并集
差集
sdiff key1 key2

把集合1和集合2的差集存储在dest中
sdiffstore dest key1 key2

交集
sinter key1 key2

sinterstore dest key1 key2

并集
sunion key1 key2

sunionstore dest key1 key2

网友评论