简体   繁体   中英

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 . However, using zscan_iter gives me the items starting from 0. Is there a way to reverse the order? Unfortunately, reverse() only works on iterators and not on python generators.

I see two solutions:

  1. Use negative priorities (so instead of 3 use -3)
  2. Paginate through slices of keys using ZREVRANGEBYSCORE , however I would prefer to use an iterator.

Are there any other ways of doing this?

Scanning the Sorted Set with an iterator does not guarantee any order. Use ZREVRANGEBYSCORE for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM