npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-context-redis

v1.0.7

Published

node red custom context storage for the redis.

Downloads

20

Readme

Redis plugin

The Redis plugin holds context data in the Redis.

Pre-requisite

To run this you need a Redis server running. For details see the Redis site.

Install

  1. Run the following command in your Node-RED user directory - typically ~/.node-red

    npm install node-red-contrib-context-redis

  2. Add a configuration in settings.js:

contextStorage: {
    custom: {
        module: require("node-red-contrib-context-redis"),
        config: {
            // see below options
        }
    }
}

Options

This plugin exposes some options defined in node_redis as itself options. It needs following configuration options:

| Options | Description | | -------------- | ----------------------------------------------------------------------------------------------------------- | | host | The IP address of the Redis server. Default: "127.0.0.1" | | port | The port of the Redis server. Default: 6379 | | db | The Redis logical database to connect. Default: 0 | | prefix | If set, the string used to prefix all used keys. | | username | If set, the plugin will run Redis AUTH command on connect. Note: the username will be sent as plaintext. | | password | If set, the plugin will run Redis AUTH command on connect. Note: the password will be sent as plaintext. |

see https://github.com/NodeRedis/node_redis#options-object-properties

Example

        contextStorage: {
            custom: {
                module: require("node-red-contrib-context-redis"),
                config: {
                    prefix: process.env.APP_NAME || "appname",
                    host: process.env.REDIS_HOST || "localhost",
                    port: process.env.REDIS_PORT || 6379,
                    db: process.env.REDIS_DB || 0,
                    username: process.env.REDIS_USERNAME || "",
                    password: process.env.REDIS_PASSWORD || "",
                    // see below options
                }
            }
        },

Data Model

Node-RED                      Redis
+-------------------+         +-------------------------------+
| global context    |         | logical database              |
| +---------------+ |         | +---------------------------+ |
| | +-----+-----+ | |         | | +-----------------+-----+ | |
| | | key |value| | | <-----> | | | global:key      |value| | |
| | +-----+-----+ | |         | | +-----------------+-----+ | |
| +---------------+ |         | |                           | |
|                   |         | |                           | |
| flow context      |         | |                           | |
| +---------------+ |         | |                           | |
| | +-----+-----+ | |         | | +-----------------+-----+ | |
| | | key |value| | | <-----> | | | <flow's id>:key |value| | |
| | +-----+-----+ | |         | | +-----------------+-----+ | |
| +---------------+ |         | |                           | |
|                   |         | |                           | |
| node context      |         | |                           | |
| +---------------+ |         | |                           | |
| | +-----+-----+ | |         | | +-----------------+-----+ | |
| | | key |value| | | <-----> | | | <node's id>:key |value| | |
| | +-----+-----+ | |         | | +-----------------+-----+ | |
| +---------------+ |         | +---------------------------+ |
+-------------------+         +-------------------------------+
  • This plugin uses a Redis logical database for all context scope.
  • This plugin prefixes all used keys with context scope in order to identify the scope of the key.
    • The keys of global context will be prefixed with global: . e.g. Set "foo" to hold "bar" in the global context -> Set "global:foo" to hold "bar" in the Redis logical database.
    • The keys of flow context will be prefixed with <id of the flow>: . e.g. Set "foo" to hold "bar" in the flow context whose id is 8588e4b8.784b38 -> Set "8588e4b8.784b38:foo" to hold "bar" in the Redis.
    • The keys of node context will be prefixed with <id of the node>: . e.g. Set "foo" to hold "bar" in the node context whose id is 80d8039e.2b82:8588e4b8.784b38 -> Set "80d8039e.2b82:8588e4b8.784b38:foo" to hold "bar" in the Redis.

Data Structure

  • This plugin converts a value of context to JSON and stores it as string type to the Redis.
  • After getting a value from the Redis, the plugin also converts the value to an object or a primitive value.
Node-RED                                 Redis
+------------------------------+         +---------------------------------------------+
| global context               |         | logical database                            |
| +--------------------------+ |         | +-----------------------------------------+ |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| | | str    | "foo"       | | | <-----> | | | global:str    | "\"foo\""           | | |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| | | num    | 1           | | | <-----> | | | global:num    | "1"                 | | |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| | | nstr   | "10"        | | | <-----> | | | global:nstr   | "\"10\""            | | |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| | | bool   | false       | | | <-----> | | | global:bool   | "false"             | | |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| | | arr    | ["a","b"]   | | | <-----> | | | global:arr    | "[\"a\",\"b\"]"     | | |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| | | obj    | {foo,"bar"} | | | <-----> | | | global:obj    | "{\"foo\",\"bar\"}" | | |
| | +--------+-------------+ | |         | | +---------------+---------------------+ | |
| +--------------------------+ |         | +-----------------------------------------+ |
+------------------------------+         +---------------------------------------------+

Other Redis client(e.g. redis-cli) can get the value stored by Node-RED like followings.

Node-RED

global.set("foo","bar");
global.set("obj",{key:"value"});

flow.set("name","alice")
await flow.get("name")

msg.payload = {}
global.set("fookey","globalfooval")
flow.set("fookey","flowfooval")
msg.payload.fookey = await global.get("fookey")
msg.payload.flowfookey = await flow.get("fookey")
console.log(await global.get("fookey"))
console.log(await flow.get("fookey"))
return msg;

redis-cli

redis> GET global:foo
"\"var\""
redis> GET global:obj
"{\"key\":\"value\"}"
redis>