当前位置:网站首页>Redis 使用LIST做最新评论缓存
Redis 使用LIST做最新评论缓存
2022-07-31 03:19:00 【Mar丶流年】
实现
假设商品 a,当前有五条评论 1,2,3,4,5。从数据库同步至redis,这里我们要求最新评论放在队首。
lpush a_comments 1
lpush a_comments 2
lpush a_comments 3
lpush a_comments 4
lpush a_comments 5
这时用户对a产生了新评论6,先入数据库,再入redis
lpush a_comments 6
查询,这里以2条为一页,先统计条数
llen a_comments
得到6条数据,页数 6/2 = 3
最新评论分页数据
# 第一页 6,5
lrange a_comments 0 1
# 第二页 4,3
lrange a_comments 2 3
# 第三页 2,1
lrange a_comments 4 5
缺陷
上面看上去好像没有啥问题,假设你现在看第一页评论,看见了6,5。这时候新产生一条评论7,加到队首。这时候你在看第二页,就不是 4,3 了。而是 5,4。这5你明明在第一页看过了。
边栏推荐
- Use of QML
- CorelDRAW2022 streamlined Asia Pacific new features in detail
- Why SocialFi achievement Web3 decentralized social in the future
- 遗留系统的自动化策略
- LeetCode每日一练 —— 138. 复制带随机指针的链表
- 【AUTOSAR-RTE】-5-Explicit(显式)和Implicit(隐式) Sender-Receiver communication
- VS QT——ui不显示新添加成员(控件)||代码无提示
- Local area network computer hardware information collection tool
- Difference between unallocated blocks and unused blocks in database files
- MultipartFile file upload
猜你喜欢

【动态规划】连续子数组的最大和

SQL injection Less54 (limited number of SQL injection + union injection)

【C语言】表达式求值的一般方法

LeetCode每日一练 —— OR36 链表的回文结构

What is a distributed lock?Three ways of implementing distributed lock

接口测试关键技术

【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法

Getting Started with CefSharp - winform

Just debuted "Fight to Fame", safety and comfort are not lost

SQL injection Less46 (injection after order by + rand() Boolean blind injection)
随机推荐
【动态规划】连续子数组的最大和
接口测试关键技术
The distance value between two arrays of LeetCode simple questions
立足本土,链接全球 | 施耐德电气“工业SI同盟”携手伙伴共赴未来工业
想从手工测试转岗自动化测试,需要学习哪些技能?
Mysql 45 study notes (twenty-five) MYSQL guarantees high availability
浅识Flutter 基本组件之CheckBox组件
SonarQube的BUG定义
什么是系统?
Atomic operation CAS
C primer plus学习笔记 —— 8、结构体
Why SocialFi achievement Web3 decentralized social in the future
[C language] Preprocessing operation
WebSocket Session为null
CefSharp入门-winform
自己的一些思考
Several common errors when using MP
刚出道“一战成名”,安全、舒适一个不落
Chapter 9 SVM实践
3.5 】 【 Cocos Creator slow operating system to stop all animations