当前位置:网站首页>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你明明在第一页看过了。
边栏推荐
- [Compilation principle] Lexical analysis program design principle and implementation
- 数据库实现分布式锁
- Redis实现分布式锁
- 浅识Flutter 基本组件之CheckboxListTile组件
- SQALE 是什么
- Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
- Automation strategies for legacy systems
- Just debuted "Fight to Fame", safety and comfort are not lost
- SQL injection Less54 (limited number of SQL injection + union injection)
- 数据库文件中的未分配的块和未使用的块的区别
猜你喜欢

5. How does the SAP ABAP OData service support the $filter operation

IIR filter and FIR filter

浅识Flutter 基本组件之showDatePicker方法

LeetCode简单题之找到和最大的长度为 K 的子序列

Use of QML

Compile Hudi

Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!

Chapter 9 SVM实践

接口测试关键技术

品牌广告投放平台的中台化应用与实践
随机推荐
分布式系统架构需要解决的问题
Key Technologies of Interface Testing
Golang中的addressable
[Godot][GDScript] 二维洞穴地图随机生成
C# remote debugging
SQL injection Less47 (error injection) and Less49 (time blind injection)
Analysis summary - self-use
The Map Entry understanding and application
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
LeetCode中等题之分数加减运算
MultipartFile file upload
Moxa NPort device flaw could expose critical infrastructure to devastating attack
Point Cloud DBSCAN Clustering (MATLAB, not built-in function)
C#远程调试
数据库实现分布式锁
【动态规划】连续子数组的最大和
[Godot][GDScript] 2D cave map randomly generated
LeetCode简单题之找到和最大的长度为 K 的子序列
Office automation case: how to automatically generate period data?
CloudCompare & PCL calculate the degree of overlap between two point clouds