当前位置:网站首页>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你明明在第一页看过了。
边栏推荐
- LeetCode每日一练 —— 138. 复制带随机指针的链表
- Mysql 45 study notes (23) How does MYSQL ensure that data is not lost
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
- 注解用法含义
- els block to the left to move the conditional judgment
- 递归查询单表-单表树结构-(自用)
- [Dynamic programming] Maximum sum of consecutive subarrays
- CloudCompare & PCL calculate the degree of overlap between two point clouds
- Recursive query single table - single table tree structure - (self-use)
- 【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
猜你喜欢
[C language] Three-pointed chess (classic solution + list diagram)
Mysql 45 study notes (23) How does MYSQL ensure that data is not lost
What is a distributed lock?Three ways of implementing distributed lock
Recursive query single table - single table tree structure - (self-use)
What skills do I need to learn to move from manual testing to automated testing?
web容器及IIS --- 中间件渗透方法1
TCP详解(二)
5. How does the SAP ABAP OData service support the $filter operation
【C语言】三子棋(经典解法+一览图)
Installation of mysql5.7.37 under CentOS7 [perfect solution]
随机推荐
冒泡排序、选择排序、直接插入排序、二分法查找
els 方块向右移
Problems that need to be solved in distributed system architecture
12 Disk related commands
3.5 】 【 Cocos Creator slow operating system to stop all animations
LeetCode simple problem to find the subsequence of length K with the largest sum
What is a distributed lock?Three ways of implementing distributed lock
自己的一些思考
With 7 years of experience, how can functional test engineers improve their abilities step by step?
SocialFi 何以成就 Web3 去中心化社交未来
2022牛客多校联赛第四场 题解
识Flutter 基本组件之showTimePicker 方法
A brief introduction to the CheckBox component of the basic components of Flutter
【HCIP】ISIS
The distance value between two arrays of LeetCode simple questions
What is distributed and clustered?What is the difference?
Why SocialFi achievement Web3 decentralized social in the future
Golang中的addressable
Automation strategies for legacy systems
Chapter 9 SVM实践