Node-js with Redis

var redis = context.global.get('redis');
client = redis.createClient(6379,'localhost');
var test=client.hget('hash key','hashtest 1', function(err, results) {
if (err) {
} else {
// do something with results
console.log(results);
client.quit();

}

});
console.log("Value=="+test);
msg.payload={"Value":test};
return msg;

When I am executing this code ,I am getting this output ,
Value==false
{"Value":false}

Please help me out.
Thank you.

If you share code, please format it properly using ```

Your Redis request returns the data in a callback function, so that part runs asynchronously and gets executed after your log output. You need to send the data inside your callback function using node.send(msg). Have a look at the docs under "Sending messages asynchronously".

I would consider using one of the existing Redis nodes found here. That makes it a lot easier than doing this in a function node.

NOTE: I would recommend this one, I have been using it myself for some time now.

Thanks a lot, the issue got solved.

Given the multiple threads you started where was the issue solved?
Then the thread becomes useful to other users in the future

1 Like

This thread issue was solved .

Where? How?
What was the answer?

Make this thread useful to others finding it in the future

var redis = context.global.get('redis');
client = redis.createClient(6379,'localhost');
client.hget('0000f8f005f1','OutBound', function(err, results) {
    if (err) {
       console.log(err);
    } else {
       console.log(results);
       client.quit();
       node.send({payload:results});
    }
 });

'0000f8f005f1' what is this value in this code?

Its the key

Maybe look at the redis docs ?
https://redis.io/commands/hget

Hello @dceejay i need to fetch the data from redis in node-red, can you help me out with this?

@Iliyas please use the topic you have already started - Fetching data from redis database

@Iliyas please stop posting to this topic. Use the separate one you have started.