Skip to content Skip to sidebar Skip to footer

Storing Redis Hget Values Into A Variable In Nodejs

const redis = require('redis'); var client = redis.createClient(); client.on('error', function(err){ console.log('Something went wrong ', err) }); var getResponse = (key, fiel

Solution 1:

You can use callbacks like:

vargetResponse = (key, field, success, error) =>{
    client.hget(key,field, function(err,reply){
        if(!err) {
           success(reply);
         }
       else {
          error(err);
        }
   });
};

getResponse("employee","b",functionsuccess(reply){
    //here you get the reply
}, functionerror(err) {
        //error
});

If you are using Node version 6 or above you can use promise or async await. You can find more details on the following link: http://exploringjs.com/es6/ch_promises.html

Post a Comment for "Storing Redis Hget Values Into A Variable In Nodejs"