[英]How to traverse a sorted set in Redis in reverse order using zscan?
I have a sorted set in Redis with priorities starting from 0 up to 3. I would like to traverse this sorted set from highest to lowest priority using the python iterator zscan_iter
. 我在Redis中有一个排序集,优先级从0到3.我想使用python iterator zscan_iter
从最高优先级到最低优先级遍历这个有序集。 However, using zscan_iter
gives me the items starting from 0. Is there a way to reverse the order? 但是,使用zscan_iter
给我从0开始的项目。有没有办法扭转顺序? Unfortunately, reverse()
only works on iterators and not on python generators. 不幸的是, reverse()
只适用于迭代器而不适用于python生成器。
I see two solutions: 我看到两个解决方案:
ZREVRANGEBYSCORE
, however I would prefer to use an iterator. 使用ZREVRANGEBYSCORE
通过切片键分页,但我更喜欢使用迭代器。 Are there any other ways of doing this? 有没有其他方法可以做到这一点?
Scanning the Sorted Set with an iterator does not guarantee any order. 使用迭代器扫描排序集并不保证任何订单。 Use ZREVRANGEBYSCORE
for that. 使用ZREVRANGEBYSCORE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.