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

Redis

Redis 输入(Input)从 Redis 读取数据,同时支持单机(standalone)与集群(cluster)两种连接模式,并提供 Subscribe(频道/模式)与 List 两种消费模式。作为通道型输入,它遵循引擎的取消安全契约:取消一次未完成的 read 不会丢失已解码的消息(参见输入投递语义)。

配置​

FieldTypeRequiredDefault描述
typestringyes—常量值 "redis"
modeobjectyes—连接模式(带标签的枚举),见下表
redis_typeobjectyes—消费模式(带标签的枚举),见下表

mode​

FieldTypeRequired描述
typestringyes"single" 或 "cluster"
urlstringyes (single)单机 URL,如 redis://host:6379
urlsarray<string>yes (cluster)集群节点 URL 列表

redis_type (subscribe)​

FieldTypeRequired描述
typestringyes"subscribe"
subscribeobjectyes订阅配置,见下文

subscribe:

FieldTypeRequired描述
typestringyes"channels" 或 "patterns"
channelsarray<string>yes (channels)频道列表
patternsarray<string>yes (patterns)模式列表

redis_type (list)​

FieldTypeRequired描述
typestringyes"list"
listarray<string>yes要消费的 Redis list 键列表

示例​

input:
type: "redis"
mode:
type: "single"
url: "redis://localhost:6379"
redis_type:
type: "subscribe"
subscribe:
type: "channels"
channels:
- "news"
- "events"
input:
type: "redis"
mode:
type: "single"
url: "redis://localhost:6379"
redis_type:
type: "list"
list:
- "tasks"
- "notifications"

持久性​

两种模式都使用空操作(Noop)确认,投递语义至多为一次(at-most-once):

  • List 模式是破坏性消费(BLPOP):元素一旦弹出就从 Redis 移除。若流水线在投递后失败或崩溃,该消息即丢失——无法重读。
  • Subscribe 模式受 Redis 语义约束,即发即忘:消费者宕机或重连期间发布的消息永远不会被投递。

上文的取消安全保证只保护"已解码消息不会因取消未完成的 read 而丢失"——它不使数据源可重放。需要持久消费时,请用可重放的数据源(如 Kafka),或在支持重放的源上开启流级 WAL 持久化。

错误行为​

暂态失败(连接断开、超时、IO)以 Disconnection 上报,引擎带退避重连;确定性拒绝(认证、权限、未知命令)在两种模式下都是致命的:订阅模式下由 connect() 上报,List 模式的轮询器会直接转发而不是死循环。暂态/永久判定是结构化的(依据驱动的错误类别与精确协议码,如 NOAUTH/WRONGPASS/NOPERM),从不依据消息措辞:消息里仅含 "invalid" 一词不会把暂态错误翻成致命错误。每次重连尝试的 connect() 失败(如服务端宕机期间)由内核重连循环持续重试,直到连接成功。