javascript - Multiple values from redis with nodejs -


i've been trying figure out how achieve nodejs , redis:

    var var1 = redisclient.get("foo");      var var2 = redisclient.get("bar");      if (var1 && var2) {          do_something();      } else {          do_something_else();      }

i know redis calls asynchronous repeating like:

var var1, var2;  redisclient.get("foo", function(err, data) {    var1 = data;    redisclient.get("bar", function(err, data) {      var2 = data;            if (var1 && var2) {        do_something();       } else {        do_something_else();      }    }  });

doesn't feel right every time want access 2 variables.

you can use async library control flow:

    async.parallel([          function(done) {              redisclient.get("foo",done);          },          function(done) {              redisclient.get("bar",done);          }        ],        function(err, result) {              //result[0] here foo             //result[1] here bar        }) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -