node.js - NodeJS 和 Redis : getting three values simultaneously

标签 node.js redis get node-redis

目前我这样做是为了使用 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/

相关文章:

javascript - Node.js:如何测试函数

redis - redis 中的排序集可以存储的成员数是否有上限?

database - Cassandra DB 或 Mongo DB 可以用于配置多个数据库吗?

php - 如何在 URL 中传递多维关联数组

C# - 获取初始页面的 HTTP 请求

javascript - jQuery AJAX $.ajax 和 $.get 不会在成功或失败条件下发出警报

node.js - 如何在 Mongoose 中进行聚合 + 填充

javascript - 编译 ejs 时 <filepath> 中出现意外的 "/"

Node.js Express + Jade(内衬项目上的事件类)

caching - 为什么功能测试会在我的 Redis 查询缓存上创建新记录?