{
  "id": "redis-stream-example",
  "title": "Write to a Redis stream",
  "url": "https://redis.io/docs/latest/integrate/redis-data-integration/data-pipelines/transform-examples/redis-stream-example/",
  "summary": "",
  "tags": [
    "docs",
    "integrate",
    "rs",
    "rdi"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "988dccb5f30375ee2b19241da6de8b158fb7188f56f23915483fd7de2d98fc62",
  "sections": [
    {
      "id": "content",
      "title": "Content",
      "role": "content",
      "text": "In the example below, data is captured from the source table named `invoice` and is written to a Redis stream. The `connection` is an optional parameter that refers to the corresponding connection name defined in `config.yaml`. \nWhen you specify the `data_type` parameter for the job, it overrides the system-wide setting `target_data_type` defined in `config.yaml`. \n\nWhen writing to streams, you can use the optional parameter `mapping` to limit the number of fields sent in a message and to provide aliases for them. If you don't use the `mapping` parameter, all fields captured in the source will be passed as the message payload. \n\nNote that streams are different from other data structures because existing messages are never updated or deleted. Any operation in the source will generate a new message with the corresponding operation code (`op_code` field) that is automatically added to the message payload. \n\nIn this case, the result will be a Redis stream with the name based on the key expression (for example, `invoice:events`) and with an expiration of 100 seconds for the whole stream. If you don't supply an `expire` parameter, the keys will never expire. \n\nIn the example, only three original fields are passed in the message payload: `InvoiceId` (as `message_id`), `BillingCountry` (as `country`), `Total` (as `Total`, no alias provided) and `op_code`, which is implicitly added to all messages sent to streams.    \n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "content-ex0",
      "language": "yaml",
      "code": "name: Write invoice events to stream\nsource:\n  schema: public\n  table: invoice\noutput:\n  - uses: redis.write\n    with:\n      connection: target\n      data_type: stream\n      key:\n        expression: \"`invoice:events`\"\n        language: jmespath\n      mapping:\n        - InvoiceId: message_id\n        - BillingCountry: country\n        - Total\n      expire: 100",
      "section_id": "content"
    }
  ]
}
