【问题标题】:How to traverse a sorted set in Redis in reverse order using zscan?如何使用zscan以相反的顺序遍历Redis中的排序集?
【发布时间】:2018-01-05 14:37:11
【问题描述】:

我在 Redis 中有一个排序集,优先级从 0 到 3。我想使用 python 迭代器 zscan_iter 遍历这个排序集从最高优先级到最低优先级。但是,使用zscan_iter 会给我从 0 开始的项目。有没有办法颠倒顺序?不幸的是,reverse() 仅适用于迭代器,不适用于 python 生成器。

我看到了两种解决方案:

  1. 使用负优先级(所以使用 -3 而不是 3)
  2. 使用 ZREVRANGEBYSCORE 对键切片进行分页,但我更喜欢使用迭代器。

还有其他方法吗?

【问题讨论】:

    标签: python redis iterator redis-py


    【解决方案1】:

    使用迭代器扫描排序集保证任何顺序。为此使用ZREVRANGEBYSCORE

    【讨论】:

      猜你喜欢
      • 2011-11-02
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      相关资源
      最近更新 更多