Redis学习笔记(七)Redis数据存储类型之sorted_set

sorted_set

​ 基本操作

​ (1)添加数据 zadd key score1 member1 score2 member2…

​ (2)获取全部数据 zrange key start stop withscores

​ zrevrange key start stop withscores

​ (3)删除数据

​ zrem key member1 member2…

​ (4) 按条件获取数据 zrangebyscore key min max withscores limit

​ zrevrangebyscore key max min withscores limit

​ (5)按条件删除数据 zremrangebyscore key min max

​ zremrangebyrank key start stop

​ (6)获取集合数据总量 zcard key

​ zcard key min max

​ (7) 集合的交,并操作 zinterstore destination numkeys key1 key2…

​ zunionstore destination numkeys key1 key2…

​ (8)求两个集合的交,并,差集并存储到指定集合中

​ sinterstore destionation key1 key2

​ sunionstore destionation key1 key2

​ (9)获取数据对应的索引 zrank key member

​ zrevrank key member

​ (2)score值获取以及修改 zscore key member

​ zincrby key increment member

​ (3)删除数据

​ zrem key member1 member2…

​ (4) 按条件获取数据 zrangebyscore key min max withscores limit

​ zrevrangebyscore key max min withscores limit

​ (5)按条件删除数据 zremrangebyscore key min max

​ zremrangebyrank key start stop

应用场景实例:

1.网站上的排名

​ 不仅要对资源进行排序,同时还需要获取到排序后的资源的索引,以便形成排行

​ 大致结构如下:

​ zadd movies 143 aa 99 bb 100 cc

​ zrank movies bb

2.带有权重的任务/消息队列

​ 通过score来记录任务的权重

​ 大体结构如下:

​ zadd task 3 order:id001

​ zadd task 1 order:id014

​ zadd task 9 order:id025

​ zrevrange task 0 -1 withscores

​ zrevrange task 0 0 withscores

​ zrem task order:id025

你可能感兴趣的:(Redis,redis,java)