目前我这样做是为了使用 node-redis 在 NodeJS 和 Redis 中获取许多值:
redis.get('data1', function(err, data1)
{
redis.get('data2', function(err, data2)
{
redis.get('data3', function(err, data3)
{
if (data3 == xx && data2 == xx && data3 == xx)
{
console.log('its ok');
}
});
});
});
问题是三个请求会一个接一个,我想一次做3个,然后像这样调用我的条件(这不起作用,只是为了让你明白我想要什么):
redis.get('data1', function(err, data1) { var data1 = data1; });
redis.get('data2', function(err, data2) { var data2 = data2; });
redis.get('data3', function(err, data3) { var data3 = data3; });
// When the 3 get operations was finished
if (data3 == xx && data2 == xx && data3 == xx)
{
console.log('its ok');
}
提前致谢
最佳答案
MGET可能是最快的,而不是来回 3 次:
client.mget(["data1", "data2", "data3"], function (err, res) {
console.dir(res);
});
关于node.js - NodeJS 和 Redis : getting three values simultaneously,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29111523/