set 特点
- 无序
- 无重复
- 集合间操作
set 基本命令
-
sadd key element
O(1) -
srem key element
O(1) scard key
sismember key member
srandmember key count
spop key
smembers key
set 间命令
sdiff user:1:follow user:2:follow
sinter user:1:follow user:2:follow
sunion user:1:follow user:2:follow
sdiff|sinter|sunion store destkey
实战
-
spop
用于抽奖 - 标签
- 给用户添加标签
sadd user:1:tags tag1 tag2 tag3
- 给标签添加用户
sadd tag1:users user1 user2 user3
- 这两个操作是在同一个事务中的;
- 给用户添加标签