Skip to main content

Redis

Use a Redis connection to read values that another program stores in a Redis database. A mapping entry reads one Redis key and publishes it on one node. The gateway only reads from Redis.

redis: is a top-level key of the configuration file. It is not inside brownfieldDevices:.

Words on this page​

WordMeaning
connectionOne entry of redis:. It has a name: and an endpoint:.
Redis keyThe name of a value in the Redis database.
DataValueAn OPC UA value with a status code and a time stamp.

How to connect a Redis database​

  1. Add redis: at the top level of the configuration file.
  2. Add an entry with name: and endpoint:.
  3. In mapping:, add an entry with node: and value: $redisGet("<connection>","<key>").
  4. Start the gateway.
redis:
- name: r1
endpoint: redis://localhost:6379

mapping:
- node: /ua:Objects/di:DeviceSet/own:MyObject/own:MyInt32
value: $redisGet("r1","MyInt32")

Keys​

KeyRequiredMeaning
nameRequiredThe name of the connection. A mapping entry uses it.
endpointRequiredThe address of the Redis database.

Functions for a mapping entry​

FunctionWhat it reads
$redisGet("<connection>","<key>")The value of the key as a DataValue in OPC UA JSON format.
$redisGetRaw("<connection>","<key>")The value of the key as plain JSON, for example 42.

Both functions return { value, statusCode, sourceTimestamp }. $redisGetRaw takes the time stamp from the key <key>:timestamp, in milliseconds. Without that key, it uses the current time.

To calculate on the value, use $redisGetRaw:

mapping:
- node: /ua:Objects/di:DeviceSet/own:MyObject/own:MyFloat2
value: |
(
$mb := $redisGetRaw("r1","MyFloat2");
{ "value": $mb.value / 10.0 + 3.14, "statusCode": $mb.statusCode }
)

Format of a Redis key for $redisGet​

The value of the key is a DataValue in OPC UA JSON format.

{
"value": 42,
"statusCode": "Good"
}
tip

A Node-RED flow can write the values to Redis. The gateway then publishes them on the nodes.