Redis Enterprise 的后写目标示例
这redis.write
块可以在output
部分,以便将数据写入 Redis Enterprise 目标数据库。可以同时使用多个数据块将数据写入不同的数据类型。以下示例捕获在address:*
keyspace 创建一个名为json_addr
,最后,将结果写入目标 Redis Enteprise 数据库中的多个键:
source:
redis:
trigger: write-behind
key_pattern: address:*
transform:
- uses: add_field
with:
fields:
- field: "json_addr"
expression: concat(['{"city":', city, ', "zip":', zip, '}'])
language: jmespath
output:
- uses: redis.write
with:
data_type: hash
connection: target
key:
expression: concat(['addr:org_id:', org_id, ':hash'])
language: jmespath
- uses: redis.write
with:
data_type: json
key:
expression: concat(['addr:org_id:', org_id, ':json'])
language: jmespath
on_update: merge
- uses: redis.write
with:
data_type: set
key:
expression: concat(['addresses:', country])
language: jmespath
args:
member: json_addr
- uses: redis.write
with:
data_type: sorted_set
key:
expression: concat(['addrs_withscores:', country])
language: jmespath
args:
score: zip
member: json_addr
- uses: redis.write
with:
data_type: stream
key:
expression: "`addresses:events`"
language: jmespath
mapping:
- org_id: message_id
- zip: zip_code
- country
Run the following command in the source Redis Enterprise database to test the job:
127.0.0.1:12005> hset address:1 city Austin zip 78901 org_id 1 country USA
The result is five keys will be created in the target Redis Enterprise database (hash, JSON, set, sorted set, and stream):
127.0.0.1:12000> keys *
1) "addr:org_id:1:hash"
2) "addr:org_id:1:json"
3) "addresses:USA"
4) "addrs_withscores:USA"
5) "addresses:events"