写入 Redis 流
在下面的示例中,数据是从名为invoice
并写入 Redis 流。这connection
是一个可选参数,它引用config.yaml
.
当您指定data_type
参数,它会覆盖系统范围的设置target_data_type
定义于config.yaml
.
写入流时,您可以使用可选参数mapping
限制消息中发送的字段数并为其提供别名。如果您不使用mapping
参数,则源中捕获的所有字段都将作为消息有效负载传递。
请注意,流与其他数据结构不同,因为现有消息永远不会更新或删除。源中的任何作都会生成一条带有相应作代码 (op_code
字段),该字段会自动添加到消息负载中。
在这种情况下,结果将是一个 Redis 流,其名称基于键表达式(例如invoice:events
),并且整个流的过期时间为 100 秒。如果您不提供expire
参数,则密钥永远不会过期。
在示例中,消息有效负载中仅传递了三个原始字段:InvoiceId
(作为message_id
),BillingCountry
(作为country
),Total
(作为Total
,未提供别名)和op_code
,该消息将隐式添加到发送到流的所有消息中。
source:
server_name: chinook
schema: public
table: invoice
output:
- uses: redis.write
with:
connection: target
data_type: stream
key:
expression: "`invoice:events`"
language: jmespath
mapping:
- InvoiceId: message_id
- BillingCountry: country
- Total
expire: 100