当前位置:网站首页>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你明明在第一页看过了。
边栏推荐
- els block to the left to move the conditional judgment
- SocialFi 何以成就 Web3 去中心化社交未来
- Detailed explanation of TCP and UDP
- C# remote debugging
- What is a distributed lock?Three ways of implementing distributed lock
- addressable in Golang
- BUG definition of SonarQube
- SonarQube的BUG定义
- 【动态规划】连续子数组的最大和
- 12 Disk related commands
猜你喜欢

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

5. SAP ABAP OData 服务如何支持 $filter (过滤)操作

Redis implements distributed locks

C# remote debugging

Ambiguous method call.both

With 7 years of experience, how can functional test engineers improve their abilities step by step?

CorelDRAW2022 streamlined Asia Pacific new features in detail

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

Compile Hudi

JS function this context runtime syntax parentheses array IIFE timer delay self.backup context call apply
随机推荐
【C语言】表达式求值的一般方法
[Godot][GDScript] 2D cave map randomly generated
A brief introduction to the CheckBox component of the basic components of Flutter
What is SQALE
Why SocialFi achievement Web3 decentralized social in the future
Difference between unallocated blocks and unused blocks in database files
Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
Office automation case: how to automatically generate period data?
SocialFi 何以成就 Web3 去中心化社交未来
Modbus on AT32 MCUs
IIR滤波器和FIR滤波器
Day32 LeetCode
顺序表的实现
【CocosCreator 3.5】CocosCreator 获取网络状态
[Dynamic programming] Maximum sum of consecutive subarrays
【HCIP】ISIS
endian mode
C primer plus学习笔记 —— 8、结构体
TCP详解(二)
Chapter 9 SVM实践