Skip to content

Redis Sink ​

The Redis sink publishes query results to a Redis database.

Properties ​

Property nameOptionalDescription
addrfalseThe network address of the Redis server, such as 10.122.48.17:6379.
passwordtrueThe Redis authentication password.
dbfalseThe Redis database index, such as 0.
keyfalseThe Redis key used when keyType is single. If both key and field are set, field takes precedence.
fieldtrueThe payload field name whose value becomes the Redis key. Applies only when keyType is single. For example, if field is "deviceName" and the record is {"deviceName":"abc"}, the Redis key is "abc". Do not use data template syntax for this property.
keyTypetrueControls how data is saved to Redis: single or multiple. Default: single. In single mode, all fields are serialized to a single JSON value. In multiple mode, each field is saved as an individual key-value pair.
dataTypefalseThe Redis data type: string or list. Default: string. Delete the existing key before changing the data type.
expirationfalseExpiration time for Redis keys in seconds. This parameter applies only to string data. Default: -1 (no expiration).
rowkindFieldtrueThe payload field that specifies the row operation (such as insert or update). If omitted, all rows default to insert.

Other common sink properties are supported. Refer to sink common properties for more information.

Sample Usage ​

The following sample rule filters temperature values greater than 50 and writes the results to Redis:

/tmp/redisRule.txt ​

json
{
  "id": "redis",
  "sql": "SELECT * from demo_stream where temperature > 50",
  "actions": [
    {
      "log": {},
      "redis": {
        "addr": "10.122.48.17:6379",
        "password": "123456",
        "db": 1,
        "dataType": "string",
        "expire": "10000",
        "field": "temperature"
      }
    }
  ]
}

Updatable Sample ​

Configure rowkindField so the sink executes operations according to the action specified in each record:

json
{
  "id": "ruleUpdateAlert",
  "sql": "SELECT * FROM alertStream",
  "actions": [
    {
      "redis": {
        "addr": "127.0.0.1:6379",
        "dataType": "string",
        "field": "id",
        "rowkindField": "action",
        "sendSingle": true
      }
    }
  ]
}

Upsert Multiple Keys Sample ​

Set keyType to multiple so the sink updates multiple keys in Redis:

json
{
  "id": "ruleUpdateAlert",
  "sql": "SELECT * FROM alertStream",
  "actions": [
    {
      "redis": {
        "addr": "127.0.0.1:6379",
        "dataType": "string",
        "keyType": "multiple",
        "sendSingle": true
      }
    }
  ]
}

When the output record has the following format, temperature and humidity are stored in Redis as separate keys:

json
{
  "temperature": 40.9,
  "humidity": 30.9
}

Released under the Apache-2.0 / MIT License.