Fun With Persistence?

Two questions...

  1. Why is persistence not identified in some way in the context view?

I created a flow variable, using default in memory defined in settings.js. I then created a flow variable, using 'persistent' as localfilesystem, i.e. persistence enabled, per the settings.js.

This results in two variables, even if they have the same name in the context view...
image

It would be a good idea to some how persistence is used in the context data view, no? More user friendly IMHO. Maybe in the label/name column, so variable name (storage name) type of thing?

  1. How do you pull the flow variable value in a typical change node? I tried the following but it did not work. Of course in a function node I could do 'flow.get('time', 'persistent')' to get the value.
    image

The actual variable pulled right now is only the first found match right? So time default is pulled before time persistent given the example above?

Sample flows...

[{"id":"e7148563.aad51","type":"inject","z":"5eda2e05.dcff38","name":"Invoke","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":180,"wires":[["58babbaa.769a0c"]]},{"id":"26e13b9a.1e092c","type":"debug","z":"5eda2e05.dcff38","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":180,"wires":[]},{"id":"41e7b4cc.bd66dc","type":"inject","z":"5eda2e05.dcff38","name":"Invoke","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":300,"wires":[["51df9970.57a9d"]]},{"id":"51df9970.57a9d","type":"change","z":"5eda2e05.dcff38","name":"Default","rules":[{"t":"set","p":"payload","pt":"msg","to":"time","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":300,"wires":[["ad8f744e.f7d058"]]},{"id":"ad8f744e.f7d058","type":"debug","z":"5eda2e05.dcff38","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":300,"wires":[]},{"id":"58babbaa.769a0c","type":"function","z":"5eda2e05.dcff38","name":"Default","func":"flow.set('time', msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":180,"wires":[["26e13b9a.1e092c"]]},{"id":"ea9f0895.3ad2e","type":"inject","z":"5eda2e05.dcff38","name":"Invoke","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":220,"wires":[["648ef7d7.a34c18"]]},{"id":"14b562ff.d7c8b5","type":"debug","z":"5eda2e05.dcff38","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":220,"wires":[]},{"id":"648ef7d7.a34c18","type":"function","z":"5eda2e05.dcff38","name":"Persistent","func":"flow.set('time', msg.payload, 'persistent');\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":220,"wires":[["14b562ff.d7c8b5"]]},{"id":"beb7cb34.6f2ed8","type":"inject","z":"5eda2e05.dcff38","name":"Invoke","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":340,"wires":[["adfea59e.9ec49"]]},{"id":"adfea59e.9ec49","type":"change","z":"5eda2e05.dcff38","name":"Persistent","rules":[{"t":"set","p":"payload","pt":"msg","to":"time,persistent","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":340,"wires":[["178c7636.d93842"]]},{"id":"178c7636.d93842","type":"debug","z":"5eda2e05.dcff38","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":340,"wires":[]}]

Settings...

module.exports = {
        uiPort: process.env.PORT || 1880,

        mqttReconnectTime: 15000,
        serialReconnectTime: 15000,
        debugMaxLength: 1000,

        flowFile: 'flows.json',
        credentialSecret: "[Redacted]",

        functionGlobalContext: {
                os:require('os'),
        },

        exportGlobalContextKeys: false,

        contextStorage: {
                default: {
                        module: "memory"
                },
                persistent: {
                        module: "localfilesystem"
                },
        },

        logging: {
                console: {
                        level: "info",
                        metrics: false,
                        audit: false
                }
        },

        editorTheme: {
                projects: {
                        enabled: false
                }
        }
}

Hi @Nodi.Rubrum

that is strange. When I use the same contextStorage setting as you have, then the editor knows I have multiple context stores and the UI reflects that.

For example, the Change node (and all other users of the TypedInput widget) offers an option on which store to use:

The Context sidebar includes labels for the store a value is in:

In the developer console of your browser, can you enter RED.settings.context and see what its value is?

Sure... Ah, hmmm... Not sure this is what you expected?

get rid of the comma, save settings.js, stop/start NR and se what happens

1 Like

Sure...Yup that was it. Now in a change node, for example, I see the selector for the persistence versus default. Funny, the very thing I was suggesting... is there! Nice. I also now see the in the context, the 'mode' of storage, persistent versus default.

Just for clarity, the extra comma had nothing to do with it. It is perfectly valid JavaScript to have a dangling comma like that, and as I said, when I tested with the exact config originally shared, it all worked as I would expect. (It would not be valid if the settings file was a JSON file).

What is far more likely is either:

  1. Node-RED wasn't restarted after the settings file was edited, or
  2. The editor wasn't reloaded after the settings file was edited and NR restarted - so the editor didn't know about the multiple context stores.

NR was restarted twice after I added the persistence settings. I changed settings file, restarted NR, and then I restarted it again, after I removed the comma.

And did you reload the editor each time?

I hit F5 both times.... But... Ctril-F5 would have forced page reload from scratch. If the page was cached?

If it had cached the settings url, that would explain it.

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