当前位置:网站首页>Redis uses sorted set to cache latest comments
Redis uses sorted set to cache latest comments
2022-07-31 03:31:00 【Mar, fleeting】
Article table of contents
Foreword
sorted set is an ordered set.The attribute of weight is provided, and data can be obtained according to the weight.
implemented
Assuming that there are reviews 11, 22, 33, 44, 55 for product A now, the weights are accumulated from 1 (+1) according to the order of reviews.
zadd a_comments 1 11zadd a_comments 2 22zadd a_comments 3 33zadd a_comments 4 44zadd a_comments 5 55
A new comment 66 was generated at this time.Determine the weight of comment 66 (total + 1)
# Get the total number of 5 and determine the weight of 6zcard a_comments# add to rediszadd a_comments 6 66
View the latest comments, 2 records per page.
# Get the current amountzcard a_comments# First page 55,66zrangebyscore a_comments 5 6# 2nd page 33,44zrangebyscore a_comments 3 4# 3rd page 11,22zrangebyscore a_comments 1 2
边栏推荐
猜你喜欢
随机推荐
Zotero如何删除自动生成的标签
addressable in Golang
LeetCode每日一练 —— 138. 复制带随机指针的链表
遗留系统的自动化策略
Automation strategies for legacy systems
Use of QML
SIP Protocol Standard and Implementation Mechanism
RESTful api接口设计规范
选好冒烟测试用例,为进入QA的制品包把好第一道关
IDEA 注释报红解决
【CocosCreator 3.5】CocosCreator get network status
IIR滤波器和FIR滤波器
endian mode
Detailed explanation of TCP (3)
C# remote debugging
els block to the left to move the conditional judgment
$parent/$children 与 ref
MP使用时的几个常见报错
Daily practice of LeetCode - palindrome structure of OR36 linked list
(线段树) 基础线段树常见问题总结