当前位置:网站首页>Redis uses LIST to cache the latest comments
Redis uses LIST to cache the latest comments
2022-07-31 03:32:00 【Mar, fleeting】
Article table of contents
implemented
Assuming product a, there are currently five reviews 1, 2, 3, 4, and 5.Synchronized from database to redis, here we require the latest comment to be placed at the top of the queue.
lpush a_comments 1lpush a_comments 2lpush a_comments 3lpush a_comments 4lpush a_comments 5At this time, the user has a new comment 6 on a, which is entered into the database first, and then into redis
lpush a_comments 6Inquiry, here are 2 items as one page, first count the number of items
llen a_commentsGet 6 pieces of data, the number of pages 6/2 = 3
The latest comment pagination data
# first page 6,5lrange a_comments 0 1# Second page 4,3lrange a_comments 2 3# 3rd page 2,1 lrange a_comments 4 5Defects
It doesn't seem like there is a problem with the above, assuming you are looking at the first page of comments now, you see 6,5.At this time, a new comment 7 is generated and added to the head of the team.At this point you are looking at the second page, it is not 4,3.Instead 5, 4.You have clearly read these 5 on the first page.
边栏推荐
猜你喜欢

Several common errors when using MP

端口排查步骤-7680端口分析-Dosvc服务

web容器及IIS --- 中间件渗透方法1

MultipartFile file upload

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

【动态规划】连续子数组的最大和

「 每日一练,快乐水题 」1331. 数组序号转换

$attrs/$listeners

LeetCode simple problem to find the subsequence of length K with the largest sum

Database implements distributed locks
随机推荐
SocialFi 何以成就 Web3 去中心化社交未来
【编译原理】递归下降语法分析设计原理与实现
VS QT——ui不显示新添加成员(控件)||代码无提示
Atomic operation CAS
Database implements distributed locks
Annotation usage meaning
RESTful api接口设计规范
WebSocket Session为null
C语言从入门到如土——数据的存储
How to develop a high-quality test case?
什么是系统?
递归查询单表-单表树结构-(自用)
【HCIP】ISIS
No qualifying bean of type 问题
Daily practice of LeetCode - 138. Copy a linked list with random pointers
分布式锁以及实现方式三种
Daily practice of LeetCode - palindrome structure of OR36 linked list
浅识Flutter 基本组件之CheckBox组件
postgresql 15源码浅析(5)—— pg_control
Redis 使用 sorted set 做最新评论缓存