Reputation: 1989
I'm using node redis
to connect to redis.
The zscan
function provided by redis does not return elements in order. I was wondering if there's a javascript
library that helps me do that.
Upvotes: 1
Views: 2129
Reputation: 22906
You can use the ZRANGE
command to scan the sorted set. You only need to record how many elements you have already scanned.
// scan from the element with the smallest score (ascending order)
var index = 0
var count = 10
ZRANGE key index index + count - 1
index += count
ZRANGE key index index + count - 1
// until all elements have been scanned
With the ZREVRANGE
command, you can also scan the sorted set in descending order.
Upvotes: 6