我有一个带有 2 个键的 Redis 服务器。我正在尝试获取两个键并将它们组合成 1 个响应。我正在使用 node-redis。
var response = {};
RedisClient.keys('*', function (err, keys) { // gets all keys
async.each( // asynchronously maps over them and parses the values
keys,
function (err, key) {
RedisClient.get(key, function (err, value) {
if (err) throw err;
responsekey] = JSON.parse(value);
});
},
function () {
res.send(response); // finally sends response object
}
);
});
这会获取所有键,异步映射它们,最后解析值并发送它们。问题是 redis 文档和我读过的每个资源都说不要使用密钥。有没有其他方法可以使用 SCAN 在节点中执行此操作?