当前位置:网站首页>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你明明在第一页看过了。
边栏推荐
- 分布式系统架构需要解决的问题
- A brief introduction to the CheckBox component of the basic components of Flutter
- [Compilation principle] Design principle and implementation of recursive descent parsing
- Chapter 9 SVM Practice
- CorelDRAW2022 streamlined Asia Pacific new features in detail
- SQL 面试用题(重点)
- Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
- JS function this context runtime syntax parentheses array IIFE timer delay self.backup context call apply
- Several common errors when using MP
- 浅识Flutter 基本组件之CheckboxListTile组件
猜你喜欢

刚出道“一战成名”,安全、舒适一个不落

C# remote debugging

Several common errors when using MP

postgresql 15源码浅析(5)—— pg_control

Office automation case: how to automatically generate period data?

接口测试关键技术

立足本土,链接全球 | 施耐德电气“工业SI同盟”携手伙伴共赴未来工业

Problems that need to be solved in distributed system architecture

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

What is distributed and clustered?What is the difference?
随机推荐
【CocosCreator 3.5】CocosCreator get network status
Difference between unallocated blocks and unused blocks in database files
C primer plus study notes - 8, structure
[Compilation principle] Lexical analysis program design principle and implementation
CloudCompare&PCL 计算两个点云之间的重叠度
What is SQALE
WebSocket Session is null
Ambiguous method call.both
Chapter 9 SVM Practice
【CocosCreator 3.5】CocosCreator 获取网络状态
MultipartFile file upload
[Dynamic programming] Maximum sum of consecutive subarrays
Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
IIR filter and FIR filter
浅识Flutter 基本组件之CheckboxListTile组件
Day32 LeetCode
TCP/IP four-layer model
SQALE 是什么
3.5 】 【 Cocos Creator slow operating system to stop all animations
SQL injection Less46 (injection after order by + rand() Boolean blind injection)