首页 > 开发 > NodeJS > 正文

nodejs redis 获取多个数据

2017-09-08 17:17:15  来源:网友分享
client.get("a", function (err, reply) {    var a = reply.toString();    console.log(a);  });client.get("b", function (err, reply) {    var b = reply.toString();    console.log(b);  });

nodejs异步 redis分别获取a,b 这样可以实现 但我不想异步回调两个函数 我想同时获取a b并且同时输出

解决方案

你想要的是这个吧,使用mget

client.mget(['sessions started', 'sessions started', 'foo'], function (err, res) {    console.dir(res);});