当前位置:网站首页>Redis 使用 sorted set 做最新评论缓存
Redis 使用 sorted set 做最新评论缓存
2022-07-31 03:19:00 【Mar丶流年】
前言
sorted set 是有序集合。提供了权重这一属性,可以按照权重大小来获取数据。
实现
假设现在A商品有评论11,22,33,44,55,这里权重按照评论先后顺序从1开始累加(+1)
zadd a_comments 1 11
zadd a_comments 2 22
zadd a_comments 3 33
zadd a_comments 4 44
zadd a_comments 5 55
这时产生了A新的评论66。确定评论66的权重(总数+1)
# 获取总数 5,确定权重6
zcard a_comments
# 添加到redis
zadd a_comments 6 66
查看最新评论,以2条记录为一页。
# 获取当前数量
zcard a_comments
# 第一页 55,66
zrangebyscore a_comments 5 6
# 第二页 33,44
zrangebyscore a_comments 3 4
# 第三页 11,22
zrangebyscore a_comments 1 2
边栏推荐
- 解析小结—自用
- 什么是系统?
- Why SocialFi achievement Web3 decentralized social in the future
- 选好冒烟测试用例,为进入QA的制品包把好第一道关
- els block to the right
- Analysis summary - self-use
- WebSocket Session为null
- web容器及IIS --- 中间件渗透方法1
- A brief introduction to the CheckBox component of the basic components of Flutter
- What is a distributed lock?Three ways of implementing distributed lock
猜你喜欢

The distance value between two arrays of LeetCode simple questions

品牌广告投放平台的中台化应用与实践

Compile Hudi

【编译原理】递归下降语法分析设计原理与实现
![[Dynamic programming] Maximum sum of consecutive subarrays](/img/3d/10731cc64d1c69d2beb3666ae0f064.png)
[Dynamic programming] Maximum sum of consecutive subarrays

Several common errors when using MP

LeetCode每日一练 —— 138. 复制带随机指针的链表

TCP和UDP详解

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

VS QT - ui does not display newly added members (controls) || code is silent
随机推荐
5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
TCP详解(一)
【Cocos Creator 3.5】缓动系统停止所有动画
postgresql 15源码浅析(5)—— pg_control
浅识Flutter 基本组件之CheckBox组件
A brief introduction to the CheckBox component of the basic components of Flutter
What is SQALE
The Map Entry understanding and application
【编译原理】递归下降语法分析设计原理与实现
With 7 years of experience, how can functional test engineers improve their abilities step by step?
Annotation usage meaning
some of my own thoughts
【HCIP】ISIS
3.5 】 【 Cocos Creator slow operating system to stop all animations
【AUTOSAR-RTE】-4-Port和Interface以及Data Type
SQL injection Less46 (injection after order by + rand() Boolean blind injection)
【C语言】进制转换一般方法
2022牛客多校联赛第四场 题解
Use of QML
Day32 LeetCode