V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ben548
V2EX  ›  Redis

Redis 的 zset 按 score 排序做分页的时候怎么保证数据不丢失?

  •  
  •   ben548 · 305 天前 via Android · 1593 次点击
    这是一个创建于 305 天前的主题,其中的信息可能已经有所发展或是发生改变。
    因为 zset 中可以存在 score 相同的数据,按 score 来查询下一页时,怎么保证下一页相同的 score 数据不丢失呢?
    9 条回复    2023-06-27 14:21:24 +08:00
    SorcererXW
        1
    SorcererXW  
       305 天前
    - 最好的办法是保证 score 不重复,score 范围这么大,计算 score 的时候多引入一些字段让 score 不冲突即可

    - 如果 score 肯定有相同的:每一次查询后,把最后那个 score 的所有项目,生成一个 bloom filter ,存下来或者透传。在查询下一页的时候,把对应的 score 的数据全拉出来,做一层过滤。
    GTim
        2
    GTim  
       305 天前
    score 是 float64 吧,你把平时的 score + 左边补 0 的 id
    guxingke
        3
    guxingke  
       305 天前
    全查 业务内存排序 sort by score , id
    ben548
        4
    ben548  
    OP
       305 天前
    @SorcererXW 好麻烦
    ben548
        5
    ben548  
    OP
       305 天前
    @guxingke ?你这个是数据库的 order by 吧,redis 不能这么干
    Dlin
        6
    Dlin  
       305 天前
    我寻思着,也没有啥丢失啊,zrange key minScore maxScore byscore limit offset count
    Dlin
        7
    Dlin  
       305 天前
    @Dlin The order of elements is from the lowest to the highest score. Elements with the same score are ordered lexicographically.
    Dlin
        8
    Dlin  
       305 天前
    @Dlin 好吧,limit 是 6.2 增加的参数
    Dlin
        9
    Dlin  
       305 天前
    可是 ZRANGEBYSCORE 也应该不会有什么问题吧?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2879 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:35 · PVG 22:35 · LAX 07:35 · JFK 10:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.