当前位置:网站首页>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你明明在第一页看过了。
边栏推荐
猜你喜欢

识Flutter 基本组件之showTimePicker 方法

Detailed explanation of TCP (1)

LeetCode中等题之分数加减运算

Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢

Ambiguous method call.both

Web container and IIS --- Middleware penetration method 1

10 Permission introduction

从滴滴罚款后数据治理思考

Moxa NPort device flaw could expose critical infrastructure to devastating attack

IDEA comment report red solution
随机推荐
C primer plus study notes - 8, structure
LeetCode中等题之分数加减运算
SocialFi 何以成就 Web3 去中心化社交未来
CloudCompare&PCL 计算两个点云之间的重叠度
CefSharp入门-winform
IIR滤波器和FIR滤波器
【编译原理】递归下降语法分析设计原理与实现
浅识Flutter 基本组件之CheckBox组件
C#远程调试
Installation of mysql5.7.37 under CentOS7 [perfect solution]
【HCIP】ISIS
MultipartFile file upload
3.5 】 【 Cocos Creator slow operating system to stop all animations
LeetCode每日一练 —— 138. 复制带随机指针的链表
数据库实现分布式锁
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
Mysql 45讲学习笔记(二十五)MYSQL保证高可用
测试中的误报和漏报同样的值得反复修正
数据库文件中的未分配的块和未使用的块的区别
Difference between unallocated blocks and unused blocks in database files