0
0
Redisquery~10 mins

XREADGROUP for consumer groups in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - XREADGROUP for consumer groups
Create Consumer Group
Consumer sends XREADGROUP
Server checks pending messages
Pending msgs?
YesDeliver pending msgs
Deliver new msgs
Consumer processes msgs
Consumer acknowledges msgs with XACK
Server removes acknowledged msgs from pending
End
This flow shows how a consumer group reads messages from a stream using XREADGROUP, handling pending and new messages, then acknowledges them.
Execution Sample
Redis
XGROUP CREATE mystream mygroup $
XREADGROUP GROUP mygroup Alice COUNT 2 STREAMS mystream >
XACK mystream mygroup 1609459200000-0 1609459200000-1
Create a group, consumer Alice reads new messages, then acknowledges both messages.
Execution Table
StepCommandActionMessages DeliveredPending MessagesNotes
1XGROUP CREATE mystream mygroup $Create consumer group 'mygroup' on 'mystream' starting at latest messageNoneNoneGroup created, no pending messages
2XREADGROUP GROUP mygroup Alice COUNT 2 STREAMS mystream >Consumer Alice reads new messages from 'mystream'2 new messages2No pending messages before read, delivers new messages, pending count increases
3XACK mystream mygroup 1609459200000-0 1609459200000-1Consumer Alice acknowledges messages with IDs 1609459200000-0 and 1609459200000-1None0Acknowledged messages removed from pending
4XREADGROUP GROUP mygroup Alice COUNT 2 STREAMS mystream >Consumer Alice reads again0 messages0No new or pending messages, returns empty
5EndNo more messages to readNone0Execution ends
💡 No more new or pending messages to deliver, consumer group read ends.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Pending Messages002000
Delivered Messages002000
Key Moments - 3 Insights
Why does XREADGROUP deliver pending messages before new messages?
Because the server first checks for pending messages (see Step 2 in execution_table). If there are pending messages, it delivers those first to avoid losing unacknowledged messages.
What does the '>' symbol mean in the XREADGROUP command?
It tells Redis to deliver new messages added to the stream after the maximum ID already delivered to the group. Pending messages for the consumer are always delivered first before new messages.
Why does the pending message count decrease after XACK?
Acknowledging a message with XACK (Step 3) tells Redis the consumer processed it, so Redis removes it from the pending list, reducing the count.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 2. How many messages does consumer Alice receive?
A0 messages
B1 pending message
C2 new messages
D3 messages
💡 Hint
Check the 'Messages Delivered' column at Step 2 in the execution_table.
At which step does the pending message count decrease?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the 'Pending Messages' column changes in the variable_tracker and execution_table.
If the consumer used '0' instead of '>' in XREADGROUP, what would change?
AIt would read only new messages
BIt would read all messages from the beginning
CIt would read only messages with ID greater than 0
DIt would read only pending messages
💡 Hint
The '>' means new messages; '0' means from the beginning or a specific ID.
Concept Snapshot
XREADGROUP reads messages for a consumer group.
It delivers pending messages first, then new messages.
Use '>' to read new messages only.
Consumers acknowledge messages with XACK.
Pending messages track unacknowledged deliveries.
Helps distribute stream processing among consumers.
Full Transcript
This visual execution trace shows how Redis XREADGROUP works for consumer groups. First, a consumer group is created on a stream. Then a consumer reads messages using XREADGROUP. Redis checks for pending messages (unacknowledged) and delivers them first. If none, it delivers new messages using the '>' ID. The consumer processes and acknowledges messages with XACK, which removes them from pending. The trace shows message delivery counts and pending message tracking step-by-step, clarifying how consumers share stream processing safely.