当前位置:网站首页>Redis 使用 sorted set 做最新评论缓存
Redis 使用 sorted set 做最新评论缓存
2022-07-31 03:19:00 【Mar丶流年】
前言
sorted set 是有序集合。提供了权重这一属性,可以按照权重大小来获取数据。
实现
假设现在A商品有评论11,22,33,44,55,这里权重按照评论先后顺序从1开始累加(+1)
zadd a_comments 1 11
zadd a_comments 2 22
zadd a_comments 3 33
zadd a_comments 4 44
zadd a_comments 5 55
这时产生了A新的评论66。确定评论66的权重(总数+1)
# 获取总数 5,确定权重6
zcard a_comments
# 添加到redis
zadd a_comments 6 66
查看最新评论,以2条记录为一页。
# 获取当前数量
zcard a_comments
# 第一页 55,66
zrangebyscore a_comments 5 6
# 第二页 33,44
zrangebyscore a_comments 3 4
# 第三页 11,22
zrangebyscore a_comments 1 2
边栏推荐
- Mysql 45 study notes (twenty-five) MYSQL guarantees high availability
- What skills do I need to learn to move from manual testing to automated testing?
- 日志级别 和 打印log注意
- 3.5 】 【 Cocos Creator slow operating system to stop all animations
- MP使用时的几个常见报错
- [Godot][GDScript] 二维洞穴地图随机生成
- Good place to download jar packages
- Detailed explanation of TCP and UDP
- 【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
- TCP详解(二)
猜你喜欢
![[C language] Three-pointed chess (classic solution + list diagram)](/img/64/18ed08b64f9618bbd7f24ee16e6a6f.jpg)
[C language] Three-pointed chess (classic solution + list diagram)

【编译原理】递归下降语法分析设计原理与实现

SIP协议标准和实现机制

IIR滤波器和FIR滤波器

What skills do I need to learn to move from manual testing to automated testing?

什么是系统?

Problems that need to be solved in distributed system architecture
![[Dynamic programming] Maximum sum of consecutive subarrays](/img/3d/10731cc64d1c69d2beb3666ae0f064.png)
[Dynamic programming] Maximum sum of consecutive subarrays

MultipartFile文件上传

Moxa NPort device flaw could expose critical infrastructure to devastating attack
随机推荐
识Flutter 基本组件之showTimePicker 方法
测试中的误报和漏报同样的值得反复修正
IDEA comment report red solution
WebSocket Session is null
【AUTOSAR-RTE】-5-Explicit(显式)和Implicit(隐式) Sender-Receiver communication
【CocosCreator 3.5】CocosCreator 获取网络状态
Good place to download jar packages
SocialFi 何以成就 Web3 去中心化社交未来
Addition and Subtraction of Scores in LeetCode Medium Questions
els 方块向右移动边界判断、向下加速
[Godot][GDScript] 2D cave map randomly generated
[Android] Room - Alternative to SQLite
Golang中的addressable
递归查询单表-单表树结构-(自用)
What is distributed and clustered?What is the difference?
BUG definition of SonarQube
Local area network computer hardware information collection tool
Redis实现分布式锁
LeetCode简单题之找到和最大的长度为 K 的子序列
SQL injection Less46 (injection after order by + rand() Boolean blind injection)