05.ZSet相关的命令


# 阻塞
BZPOPMIN key [key ...]
BZPOPMAX key [key ...]
BZPOP timeout numkeys key [key ...] MIN|MAX [COUNT count]

# 针对分数的操作
ZPOPMIN key min max
ZPOPMAX key [count]
ZMPOP numkeys key [key ...]
ZLEXCOUNT key min max

ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]
ZCARD key
ZCOUNT key min max
ZSCAN

ZINCREBY key increment member

ZSCORE
ZMSCORE

ZRANGE
ZRANGESTORE
ZRANGEBYLEX
ZREVRANGEBYLEX
ZRANGEBYSCORE

ZLEXCOUNT key min max

# 集合操作
ZINTER numkeys increment member
ZINTERCARD destination numkeys key [key ...]
ZUNION 
ZUNIONSTORE
ZDIFF numkeys key [key ...] [WITHSCORES]
ZDIFFSTORE destination numkeys key [key ...]
ZINTERSTORE numkeys key [key ...] [LIMIT limit]

数据结构

ZSet底层使用了两个数据结构:Hash和跳跃表。Hash的作用是关联元素value和权重score,保障元素value的唯一性,可以通过元素value找到相应的score值。跳跃表的目的是给元素value排序,根据score的范围获取元素列表。

参考资料

  1. Redis#SortedSet