{
  "id": "write-behind-to-redis-example",
  "title": "Write-behind to Redis Enterprise target example",
  "url": "https://redis.io/docs/latest/integrate/write-behind/data-transformation/transformation-examples/write-behind-to-redis-example/",
  "summary": "",
  "tags": [
    "docs",
    "integrate",
    "rs",
    "rdi"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "11b386443b2cc458eb49251989abb72eca5adbdd53fb6c62db82957abe808716",
  "sections": [
    {
      "id": "content",
      "title": "Content",
      "role": "content",
      "text": "The `redis.write` block can be used in the `output` section of the write-behind job in order to enable writing data to the Redis Enterprise target database. Multiple blocks can be used at the same time to write data to different data types. The following example captures data modified in the `address:*` keyspace, then creates a new JSON-like string field named `json_addr`,  and, finally, writes the results to multiple keys in target Redis Enteprise database:\n\n[code example]\n\nRun the following command in the source Redis Enterprise database to test the job:\n\n[code example]\n\nThe result is five keys will be created in the target Redis Enterprise database (hash, JSON, set, sorted set, and stream):\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "content-ex0",
      "language": "yaml",
      "code": "source:\n  redis:\n    trigger: write-behind\n    key_pattern: address:*\ntransform:\n  - uses: add_field\n    with:\n      fields:\n        - field: \"json_addr\"\n          expression: concat(['{\"city\":', city, ', \"zip\":', zip, '}'])\n          language: jmespath\noutput:\n  - uses: redis.write\n    with:\n      data_type: hash\n      connection: target\n      key:\n        expression: concat(['addr:org_id:', org_id, ':hash'])\n        language: jmespath\n  - uses: redis.write\n    with:\n      data_type: json\n      key:\n        expression: concat(['addr:org_id:', org_id, ':json'])\n        language: jmespath\n      on_update: merge\n  - uses: redis.write\n    with:\n      data_type: set\n      key:\n        expression: concat(['addresses:', country])\n        language: jmespath\n      args:\n        member: json_addr\n  - uses: redis.write\n    with:\n      data_type: sorted_set\n      key:\n        expression: concat(['addrs_withscores:', country])\n        language: jmespath\n      args:\n        score: zip\n        member: json_addr\n  - uses: redis.write\n    with:\n      data_type: stream\n      key:\n        expression: \"`addresses:events`\"\n        language: jmespath\n      mapping:\n        - org_id: message_id\n        - zip: zip_code\n        - country",
      "section_id": "content"
    },
    {
      "id": "content-ex1",
      "language": "shell",
      "code": "127.0.0.1:12005> hset address:1 city Austin zip 78901 org_id 1 country USA",
      "section_id": "content"
    },
    {
      "id": "content-ex2",
      "language": "shell",
      "code": "127.0.0.1:12000> keys *\n1) \"addr:org_id:1:hash\"\n2) \"addr:org_id:1:json\"\n3) \"addresses:USA\"\n4) \"addrs_withscores:USA\"\n5) \"addresses:events\"",
      "section_id": "content"
    }
  ]
}
