按顺序扫描redis排序集
Scan redis sorted set in order
我正在使用 node redis
连接到 Redis。
redis提供的zscan
函数没有return元素的顺序。我想知道是否有一个 javascript
库可以帮助我做到这一点。
您可以使用ZRANGE
命令扫描排序集。你只需要记录你已经扫描了多少个元素。
// 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
使用ZREVRANGE
命令,还可以按降序扫描已排序的集合。
我正在使用 node redis
连接到 Redis。
redis提供的zscan
函数没有return元素的顺序。我想知道是否有一个 javascript
库可以帮助我做到这一点。
您可以使用ZRANGE
命令扫描排序集。你只需要记录你已经扫描了多少个元素。
// 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
使用ZREVRANGE
命令,还可以按降序扫描已排序的集合。