{
  "schema_version": 2,
  "id": "integrate/redis-data-integration/data-pipelines/transform-examples/redis-sorted-set-example",
  "title": "Write to a Redis sorted set",
  "url": "https://redis.io/docs/latest/integrate/redis-data-integration/1.19.1/data-pipelines/transform-examples/redis-sorted-set-example/",
  "summary": "",
  "content": "\nIn the example below, data is captured from the source table named `invoice` and is written to a Redis sorted set. The `connection` is an optional parameter that refers to the corresponding connection name defined in `config.yaml`. When\nyou 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 sorted sets, you must provide two additional arguments, `member` and `score`. These specify the field names that will be used as a member and a score to add an element to a sorted set. In this case, the result will be a Redis sorted set named `invoices:sorted` based on the key expression and with an expiration of 100 seconds for each set member. If you don't supply an `expire` parameter, the keys will never expire.\n\n```yaml\nname: Write invoices to sorted set by total\nsource:\n  schema: public\n  table: invoice\noutput:\n  - uses: redis.write\n    with:\n      connection: target\n      data_type: sorted_set\n      key:\n        expression: \"`invoices:sorted`\"\n        language: jmespath\n      args:\n        score: Total\n        member: InvoiceId\n      expire: 100\n```\n\nSince sorted sets in Redis are inherently sorted, you can easily get the top N invoices by total invoice amount using the command below (the range 0..9 gets the top 10 invoices):\n\n```\nZREVRANGE invoices:sorted 0 9 WITHSCORES\n```\n",
  "tags": ["docs","integrate","rs","rdi"],
  "last_updated": "2026-09-19T17:55:58-07:00"
}
