# Global.get fails while using contextStorage(redis)

**URL:** <https://discourse.nodered.org/t/global-get-fails-while-using-contextstorage-redis/95183>\
**Category:** General\
**Created:** [6 February 2025 14:26 UTC](https://discourse.nodered.org/t/global-get-fails-while-using-contextstorage-redis/95183 "2025-02-06T14:26:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakonnode](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jakonnode](https://discourse.nodered.org/u/jakonnode)\
**Post date:** [6 February 2025 14:26 UTC](https://discourse.nodered.org/t/global-get-fails-while-using-contextstorage-redis/95183/1 "2025-02-06T14:26:10Z")

</div>

While using redis contextStorage as default and use global.get() it results in an error as below.

"Error: Callback must be a function"

Using the below redis package.

### [GitHub - node-red/node-red-context-redis: A Node-RED Context store plugin backed by Redis](https://github.com/node-red/node-red-context-redis)

global.set() goes through and my redis-cli has stored the value too that I can query and check.

This doesn't happen with default being filesystem (and obviously memory)

I cannot make redis context as default. I would like both durability + Transactionality hence was trying redis context storage for this purpose.

```auto
contextStorage: {
        default: {
            module: require("node-red-context-redis"),
            config: {
               host: "127.0.0.1",
               port: 6379,
               db:0,
               password:"mypassword",

            }
        },
},

```

I can selectively use redis for storing explicitly without making it default

```auto
global.set("myglobalkey","myval","redis");
context.set("mycontextkey","myval2","redis");
..
global.get("mykey","redis");
context.get("mycontextkey","redis");

```

Has anyone faced this issue?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 February 2025 14:39 UTC](https://discourse.nodered.org/t/global-get-fails-while-using-contextstorage-redis/95183/2 "2025-02-06T14:39:45Z")

</div>

Assuming you are talking about accessing values in a function node, use the callback signature. This is necessary as the storage is remote and cannot be synchronous.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/6241f097ad2dcd12e21cb1ec866d4e5ed5b49362.png)

```js
global.get("key", "redis", function(err, data) {
   if (err) {
      // didnt work
   } else {
      // worked - use the data!
      node.warn({data})
      node.send({payload: data})
   }
})

```

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [6 February 2025 14:40 UTC](https://discourse.nodered.org/t/global-get-fails-while-using-contextstorage-redis/95183/3 "2025-02-06T14:40:08Z")

</div>

Check the documentation about asynchronous context storage: [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions#asynchronous-context-access)

If context storage does not implement synchronous reads and writes (that only works with nodered core memory and file storage), you get the value inside a passed callback to get function.

This error is telling you that you did not provide that callback function when calling `get`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 May 2025 14:40 UTC](https://discourse.nodered.org/t/global-get-fails-while-using-contextstorage-redis/95183/4 "2025-05-07T14:40:25Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
