# Fun With Persistence?

**URL:** <https://discourse.nodered.org/t/fun-with-persistence/33189>\
**Category:** General\
**Created:** [22 September 2020 16:18 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189 "2020-09-22T16:18:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [22 September 2020 16:18 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/1 "2020-09-22T16:18:12Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d66e689c8195a1729a14a3659c12714a0d971b7.png)

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97c672f13df93161a878fa0c45d0dffa1e554c2a.png)

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...

```auto
[{"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...

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

```

---

<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:** [22 September 2020 16:43 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/2 "2020-09-22T16:43:15Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8bb19aa1525d43eec3d5fe4e94a72132f885c1c5.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/7572f66fca9e7f6ccf19dca0428edcd7239723cf.png)

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

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [22 September 2020 17:17 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/3 "2020-09-22T17:17:21Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce59ec3ef6126af2365c4f0e99e7c1bfe2de6106.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 September 2020 17:21 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/4 "2020-09-22T17:21:29Z")

</div>

> [@Nodi.Rubrum](#):
>
> ```auto
> contextStorage: {
> default: {
> module: "memory"
> },
> persistent: {
> module: "localfilesystem"
> }, <=========== get rid of this comma
> },
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [22 September 2020 17:25 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/5 "2020-09-22T17:25:05Z")

</div>

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.

---

<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:** [22 September 2020 19:43 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/6 "2020-09-22T19:43:52Z")

</div>

> [@zenofmud](#):
>
> get rid of the comma, save settings.js, stop/start NR and se what happens

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.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [22 September 2020 19:47 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/7 "2020-09-22T19:47:47Z")

</div>

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.

---

<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:** [22 September 2020 19:48 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/8 "2020-09-22T19:48:17Z")

</div>

And did you reload the editor each time?

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [22 September 2020 19:50 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/9 "2020-09-22T19:50:48Z")

</div>

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

---

<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:** [22 September 2020 19:51 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/10 "2020-09-22T19:51:41Z")

</div>

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

---

<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:** [21 November 2020 19:51 UTC](https://discourse.nodered.org/t/fun-with-persistence/33189/11 "2020-11-21T19:51:41Z")

</div>

Closed on 21 November 2020 19:51 UTC

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