Redis学习笔记6--Redis之Sorted-Set数据结构

1.添加元素--zadd [key1] [value1] [key2] [value2]...

注意:key必须是float类型

2.集合长度--zcard [sorted-set名称]

Redis学习笔记6--Redis之Sorted-Set数据结构

3.查看所有元素--zrange [sorted-set名称] [0] [-1] (升序排列)

zrange [sorted-set名称] [0] [-1] withscores

Redis学习笔记6--Redis之Sorted-Set数据结构

4.查看指定元素score--zscore [sorted-set名称] [元素]

Redis学习笔记6--Redis之Sorted-Set数据结构

5.删除元素--zrem [sorted-set名称] [元素]

Redis学习笔记6--Redis之Sorted-Set数据结构

6.查看所有元素--zrevrange [sorted-set名称] [0] [-1] withscores (降序排列)

Redis学习笔记6--Redis之Sorted-Set数据结构

7.根据角标范围删除元素--zremrangebyrank [sorted-set名称] [起始位置] [结束位置]

Redis学习笔记6--Redis之Sorted-Set数据结构

8.根据score删除元素--zremrangebyscore [sorted-set名称] [score1] [score2]

Redis学习笔记6--Redis之Sorted-Set数据结构

9.显示元素

zrangebyscore [sorted-set名称] [score1] [score2]

zrangebyscore [sorted-set名称] [score1] [score2] withscores

zrangebyscore [sorted-set名称] [score1] [score2] withscores limit [索引位置1] [索引位置2]

Redis学习笔记6--Redis之Sorted-Set数据结构

10.修改score--zincrby [sorted-set名称] [value] [元素a],表示在元素a的score基础上加value

Redis学习笔记6--Redis之Sorted-Set数据结构

11.返回score范围的个数--zcount [sorted-set名称] [score1] [score2]

Redis学习笔记6--Redis之Sorted-Set数据结构

12.使用场景

1>大型游戏在线积分排行榜

2>构建索引数据