# Node-js with Redis

**URL:** <https://discourse.nodered.org/t/node-js-with-redis/15708>\
**Category:** General\
**Created:** [20 September 2019 06:19 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708 "2019-09-20T06:19:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjaycoder-r](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanjaycoder-r/32/12281_2.png) [@Sanjaycoder-r](https://discourse.nodered.org/u/Sanjaycoder-r)\
**Post date:** [20 September 2019 06:19 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/1 "2019-09-20T06:19:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [20 September 2019 06:28 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/2 "2019-09-20T06:28:31Z")

</div>

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](https://nodered.org/docs/user-guide/writing-functions) under "Sending messages asynchronously".

I would consider using one of the existing Redis nodes found [here](https://flows.nodered.org/?term=redis&num_pages=1). 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.

> **[node-red-contrib-redis](https://flows.nodered.org/node/node-red-contrib-redis)**
>
> Node Red client for Redis with pub/sub, list, lua scripting and other commands support.

---

<div class="post-metadata">

**Author:** ![Sanjaycoder-r](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanjaycoder-r/32/12281_2.png) [@Sanjaycoder-r](https://discourse.nodered.org/u/Sanjaycoder-r)\
**Post date:** [20 September 2019 06:37 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/3 "2019-09-20T06:37:13Z")

</div>

Thanks a lot, the issue got solved.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 September 2019 07:38 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/4 "2019-09-20T07:38:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sanjaycoder-r](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanjaycoder-r/32/12281_2.png) [@Sanjaycoder-r](https://discourse.nodered.org/u/Sanjaycoder-r)\
**Post date:** [20 September 2019 07:42 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/5 "2019-09-20T07:42:36Z")

</div>

This thread issue was solved .

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 September 2019 07:46 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/6 "2019-09-20T07:46:59Z")

</div>

Where? How?  
What was the answer?

Make this thread useful to others finding it in the future

---

<div class="post-metadata">

**Author:** ![Sanjaycoder-r](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanjaycoder-r/32/12281_2.png) [@Sanjaycoder-r](https://discourse.nodered.org/u/Sanjaycoder-r)\
**Post date:** [20 September 2019 07:49 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/7 "2019-09-20T07:49:23Z")

</div>

```auto
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});
    }
 });

```

---

<div class="post-metadata">

**Author:** ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)\
**Post date:** [5 February 2020 07:08 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/8 "2020-02-05T07:08:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 February 2020 07:49 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/9 "2020-02-05T07:49:20Z")

</div>

Its the key

Maybe look at the redis docs ?  
[https://redis.io/commands/hget](https://redis.io/commands/hget)

---

<div class="post-metadata">

**Author:** ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)\
**Post date:** [5 February 2020 08:51 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/10 "2020-02-05T08:51:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 February 2020 09:04 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/11 "2020-02-05T09:04:48Z")

</div>

@Iliyas please use the topic you have already started - [Fetching data from redis database](https://discourse.nodered.org/t/fetching-data-from-redis-database/21292/3)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 February 2020 09:14 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/13 "2020-02-05T09:14:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 February 2020 09:14 UTC](https://discourse.nodered.org/t/node-js-with-redis/15708/14 "2020-02-05T09:14:07Z")

</div>


