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
| Word | Meaning |
|---|---|
| connection | One entry of redis:. It has a name: and an endpoint:. |
| Redis key | The name of a value in the Redis database. |
| DataValue | An OPC UA value with a status code and a time stamp. |
How to connect a Redis database
- Add
redis:at the top level of the configuration file. - Add an entry with
name:andendpoint:. - In
mapping:, add an entry withnode:andvalue: $redisGet("<connection>","<key>"). - 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
| Key | Required | Meaning |
|---|---|---|
name | Required | The name of the connection. A mapping entry uses it. |
endpoint | Required | The address of the Redis database. |
Functions for a mapping entry
| Function | What 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.