redis - 按顺序扫描redis排序集

标签 redis node-redis

我正在使用 node redis 连接到 redis。

redis提供的zscan函数返回的元素不是按顺序排列的。我想知道是否有一个 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 命令,您还可以按降序扫描已排序的集合。

关于redis - 按顺序扫描redis排序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42898374/

相关文章:

java - 在集成测试中使用 redis 禁用 spring session

node.js - node_redis 获取 zrange withscores

node.js - lpush 后的 node_redis rpop 数组

Redis - 在主从关系中即时使用 CONFIG SET

redis - 如何设置Redis在过滤key时不区分大小写?

node.js - 如何在 Heroku 上使用 Node.js 通信 Web 和 Worker dynos?

lua - StackExchange Redis客户端在使用lua时如何知道调用哪个集群节点?

node.js - 使用node-redis删除redis中的键数组

redis - 将 redis 集成到无服务器中

javascript - 无法让 socket.io-emitter 与 socket.io-redis 一起工作