跳到主要内容
版本:Next
output/redisINPUTBUFFERPROCESSOROUTPUT

Redis

Redis 输出(Output)使用四种数据结构操作之一将消息(Message)写入 Redis:Pub/Sub 发布、List 推入、Hash 写入或 String 写入。它支持单节点与集群连接。

配置​

FieldTypeRequiredDefault描述
typestringyes—固定值 "redis"
modeobjectyes—连接模式(见下文)。
redis_typeobjectyes—要执行的 Redis 操作(见下文)。
value_fieldstringno—二进制或字符串列,其逐行值作为该条消息的载荷(null 值或缺失列会报错)。未配置时按 codec 编码整批。

mode​

mode 是一个带标签对象(由其 type 字段选择)。

FieldTypeRequiredDefault描述
typestringyes—single 或 cluster。
urlstringyes (single)—Redis 服务器 URL(例如 redis://localhost:6379)。
urlsarray<string>yes (cluster)—Redis 集群节点 URL 列表。

redis_type​

redis_type 是一个带标签对象(由其 type 字段选择)。所有键/字段/频道均为 Expr<String>(参见表达式对象)。

publish​

FieldTypeRequired描述
typestringyespublish。
channelobjectyes要发布到的 Pub/Sub 频道(表达式)。

list​

FieldTypeRequired描述
typestringyeslist。
keyobjectyesList 键;值通过 RPUSH 追加(表达式)。

hashes​

FieldTypeRequired描述
typestringyeshashes。
keyobjectyesHash 键(表达式)。
fieldobjectyesHash 字段名(表达式)。

strings​

FieldTypeRequired描述
typestringyesstrings。
keyobjectyesString 键(表达式)。

表达式对象​

channel、key 与 field 是 Expr<String> 对象:

FieldTypeRequired描述
typestringyesvalue(静态)或 expr(SQL 表达式)。
valuestringyes (value)静态值。
exprstringyes (expr)对每条消息求值的 SQL 表达式。

表达式必须对每一行求出非 null 字符串:任意行为 NULL 时整批报错,错误信息指名表达式与行号(可用 COALESCE(expr, 'fallback') 规避,或在上游过滤这类行)。

示例​

发布到频道​

output:
type: "redis"
mode:
type: "single"
url: "redis://localhost:6379"
redis_type:
type: "publish"
channel:
type: "value"
value: "notifications"

推入 List​

output:
type: "redis"
mode:
type: "single"
url: "redis://localhost:6379"
redis_type:
type: "list"
key:
type: "value"
value: "events"

设置 Hash 字段​

output:
type: "redis"
mode:
type: "single"
url: "redis://localhost:6379"
redis_type:
type: "hashes"
key:
type: "value"
value: "user:1"
field:
type: "value"
value: "status"

设置 String​

output:
type: "redis"
mode:
type: "single"
url: "redis://localhost:6379"
redis_type:
type: "strings"
key:
type: "expr"
expr: "concat('key:', id)"

集群连接​

output:
type: "redis"
mode:
type: "cluster"
urls:
- "redis://redis-1:6379"
- "redis://redis-2:6379"
- "redis://redis-3:6379"
redis_type:
type: "list"
key:
type: "value"
value: "logs"