Global.get fails while using contextStorage(redis)

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

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.

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

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

Has anyone faced this issue?

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.

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

Check the documentation about asynchronous context storage: Writing Functions : Node-RED

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.

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