监控消费者组延迟
使用 XINFO 和 XPENDING 检查消费者组健康状况,测量延迟、发现停滞的消费者,并让流处理保持正常运行
监控消费者组延迟 是 CoddyKit 上的免费 Redis Caching & Messaging (Pub/Sub, Streams) 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Redis Caching & Messaging (Pub/Sub, Streams) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Redis Caching & Messaging (Pub/Sub, Streams) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Monitor Lag?
In a healthy pipeline, consumers keep up with producers. When they fall behind, lag builds up: unread or unacknowledged entries pile in the stream. Monitoring lag lets you scale consumers before backlogs become outages.
Inspecting the Stream
XINFO STREAM gives a high-level view: length, last generated ID, and the number of consumer groups attached.
XINFO STREAM ordersInspecting Groups
XINFO GROUPS lists each group with its last-delivered-id, the count of pending entries, and (in recent Redis) a lag field showing how many entries the group has not yet read.
XINFO GROUPS ordersUnderstanding Lag
The lag value is the number of entries between the group's last-delivered-id and the stream's last entry. A steadily rising lag means producers outpace consumers.
Per-Consumer Detail
XINFO CONSUMERS drills into a single group, showing each consumer's pending count and idle time. A consumer with high idle time and many pending entries is likely stuck or dead.
XINFO CONSUMERS orders workersSummarizing Pending
XPENDING with just the key and group gives a summary: total pending, the lowest and highest pending IDs, and a per-consumer breakdown.
XPENDING orders workersDetailed Pending
The extended form lists individual pending entries with their idle time and delivery count, helping you find messages that keep failing.
XPENDING orders workers - + 10Spotting Poison Messages
A high delivery count on a pending entry signals a poison message: one that repeatedly fails and gets re-delivered. Route it to a dead-letter stream after a threshold.
XADD dead-letter * original_id 1716900000-0 reason "max retries"Alerting Thresholds
Turn metrics into alerts: warn when group lag exceeds a budget, or when any consumer's idle time crosses a limit while holding pending entries. Sample these via XINFO from a monitoring job.
Reacting to Lag
When lag climbs, add consumers to the group to parallelize processing, optimize the per-message work, or increase the trim cap so the buffer can absorb spikes. Each consumer in a group gets a disjoint slice of new entries.
A Monitoring Loop
A simple monitor periodically calls XINFO GROUPS, extracts lag and pending, and emits the values to your metrics system for dashboards and alerts.
while true; do redis-cli XINFO GROUPS orders; sleep 10; doneQuick Check
Test your understanding of lag monitoring.
Recap
You learned to monitor consumer group health using XINFO STREAM/GROUPS/CONSUMERS for lag and idle time, and XPENDING for pending detail and delivery counts. Use these signals to detect poison messages, set alert thresholds, and scale consumers before backlogs grow.
常见问题解答
「监控消费者组延迟」课时是免费的吗?
是的 — 「监控消费者组延迟」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Redis Caching & Messaging (Pub/Sub, Streams) 课程的其余内容,请升级到 CoddyKit PRO。 Redis Caching & Messaging (Pub/Sub, Streams) 课程共包含 4 节课。
「监控消费者组延迟」这节课中我会学到什么?
使用 XINFO 和 XPENDING 检查消费者组健康状况,测量延迟、发现停滞的消费者,并让流处理保持正常运行 你通过在浏览器中直接运行的动手代码来练习 Redis Caching & Messaging (Pub/Sub, Streams),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Redis Caching & Messaging (Pub/Sub, Streams) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Redis Caching & Messaging (Pub/Sub, Streams) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「监控消费者组延迟」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Redis Caching & Messaging (Pub/Sub, Streams) 课中编写并运行代码吗?
能。每节 Redis Caching & Messaging (Pub/Sub, Streams) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 消费者组简介
- 实现消费者组逻辑
- 处理待处理消息与故障
- 监控消费者组延迟