Bird
Raised Fist0
Redisquery~20 mins

XREADGROUP for consumer groups in Redis - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Redis Stream Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Output of XREADGROUP with new consumer
Given a Redis stream 'mystream' with entries and a consumer group 'mygroup', what will be the output of this command?
XREADGROUP GROUP mygroup consumer1 COUNT 2 STREAMS mystream > 
Redis
XREADGROUP GROUP mygroup consumer1 COUNT 2 STREAMS mystream >
A[["mystream", [["0-0", {"field1": "value1"}]]]]
B[]
C[["mystream", [["1609459200000-0", {"field1": "value1"}], ["1609459200001-0", {"field2": "value2"}]]]]
D[["mystream", [[">", {"field1": "value1"}]]]]
Attempts:
2 left
💡 Hint
The '>' ID in XREADGROUP returns only new messages never delivered to any consumer in the group.
🧠 Conceptual
intermediate
2:00remaining
Behavior of XREADGROUP with ID '0'
What happens when you run the following command for a consumer group that already exists?
XREADGROUP GROUP mygroup consumer2 STREAMS mystream 0
AReturns no messages because '0' is invalid for XREADGROUP.
BReturns only new messages never delivered to any consumer.
CReturns only pending messages for consumer2.
DReturns all messages in the stream, including those already delivered to other consumers.
Attempts:
2 left
💡 Hint
Using '0' as the ID in XREADGROUP means to read from the beginning of the stream.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in XREADGROUP command
Which of the following XREADGROUP commands has a syntax error?
AXREADGROUP GROUP mygroup consumer1 STREAMS mystream > COUNT 5
BXREADGROUP GROUP mygroup consumer1 COUNT 5 STREAMS mystream >
CXREADGROUP GROUP mygroup consumer1 STREAMS mystream 0
DXREADGROUP GROUP mygroup consumer1 COUNT 10 STREAMS mystream 0
Attempts:
2 left
💡 Hint
The COUNT option must appear before STREAMS and stream keys.
❓ optimization
advanced
2:00remaining
Optimizing XREADGROUP for multiple streams
You want to read new messages from two streams 'stream1' and 'stream2' for consumer 'c1' in group 'g1'. Which command efficiently reads only new messages from both streams?
AXREADGROUP GROUP g1 c1 STREAMS stream1 stream2 0 0
BXREADGROUP GROUP g1 c1 COUNT 10 STREAMS stream1 stream2 > >
CXREADGROUP GROUP g1 c1 COUNT 10 STREAMS stream1 stream2 0 0
DXREADGROUP GROUP g1 c1 STREAMS stream1 stream2 > >
Attempts:
2 left
💡 Hint
Use '>' to read only new messages never delivered to any consumer in the group.
🔧 Debug
expert
2:00remaining
Why does XREADGROUP return no messages?
A consumer group 'g1' exists on stream 'mystream'. Consumer 'c1' runs:
XREADGROUP GROUP g1 c1 STREAMS mystream > COUNT 5

But it returns an empty array even though the stream has new messages. What is the most likely cause?
AThe consumer group was created with an ID higher than the new messages' IDs.
BThe COUNT option is too low to return any messages.
CThe stream 'mystream' is empty.
DThe consumer name 'c1' is not registered in the group.
Attempts:
2 left
💡 Hint
The group ID determines which messages are considered new for '>' reads.

Practice

(1/5)
1. What is the main purpose of using XREADGROUP in Redis streams?
easy
A. To backup the stream data to disk
B. To delete messages from the stream automatically
C. To create a new stream in Redis
D. To allow multiple consumers to read from the same stream without missing messages

Solution

  1. Step 1: Understand consumer groups in Redis streams

    Consumer groups allow multiple consumers to share the workload of reading messages from a stream safely.
  2. Step 2: Role of XREADGROUP command

    XREADGROUP reads messages for a specific consumer group, ensuring messages are distributed and not missed.
  3. Final Answer:

    To allow multiple consumers to read from the same stream without missing messages -> Option D
  4. Quick Check:

    Purpose of XREADGROUP = safe multi-consumer reading [OK]
Hint: XREADGROUP is for sharing stream reads among consumers [OK]
Common Mistakes:
  • Thinking XREADGROUP deletes messages
  • Confusing XREADGROUP with stream creation
  • Assuming it backs up data automatically
2. Which of the following is the correct syntax to read messages from a consumer group using XREADGROUP?
easy
A. XREADGROUP GROUP consumername groupname STREAMS mystream >
B. XREADGROUP STREAMS mystream GROUP groupname consumername >
C. XREADGROUP GROUP groupname consumername STREAMS mystream >
D. XREADGROUP STREAMS > mystream GROUP groupname consumername

Solution

  1. Step 1: Recall the correct order of XREADGROUP syntax

    The correct syntax is: XREADGROUP GROUP <groupname> <consumername> STREAMS <stream> <id>
  2. Step 2: Match options with syntax

    XREADGROUP GROUP groupname consumername STREAMS mystream > matches the correct order and keywords exactly.
  3. Final Answer:

    XREADGROUP GROUP groupname consumername STREAMS mystream > -> Option C
  4. Quick Check:

    Syntax order = GROUP then consumer then STREAMS [OK]
Hint: GROUP keyword comes right after XREADGROUP [OK]
Common Mistakes:
  • Swapping groupname and consumername order
  • Placing STREAMS before GROUP
  • Misplacing the '>' symbol
3. Given a Redis stream mystream with messages and a consumer group group1, what will be the output of this command?
XREADGROUP GROUP group1 consumer1 STREAMS mystream 0
medium
A. An error because 0 is invalid ID
B. All pending and new messages from the stream for consumer1
C. Only new messages added after the command runs
D. No messages because 0 means no messages

Solution

  1. Step 1: Understand the meaning of ID '0' in XREADGROUP

    Using '0' as the ID means the consumer wants to read all pending messages (not yet acknowledged) plus new messages.
  2. Step 2: Effect on output

    The command returns all pending messages for consumer1 and any new messages added after the command runs.
  3. Final Answer:

    All pending and new messages from the stream for consumer1 -> Option B
  4. Quick Check:

    ID '0' = pending + new messages [OK]
Hint: ID '0' fetches pending plus new messages [OK]
Common Mistakes:
  • Thinking '0' causes error
  • Assuming only new messages are returned
  • Believing '0' means no messages
4. You run this command but get an error:
XREADGROUP GROUP group1 consumer1 STREAMS mystream >

What is the likely cause?
medium
A. The consumer group 'group1' does not exist
B. The stream 'mystream' is empty
C. The consumer name 'consumer1' is invalid
D. The '>' symbol is misplaced

Solution

  1. Step 1: Check prerequisites for XREADGROUP

    XREADGROUP requires the consumer group to exist before reading messages.
  2. Step 2: Identify cause of error

    If the group 'group1' does not exist, Redis returns an error when running XREADGROUP.
  3. Final Answer:

    The consumer group 'group1' does not exist -> Option A
  4. Quick Check:

    Missing group = error on XREADGROUP [OK]
Hint: Create group before reading with XREADGROUP [OK]
Common Mistakes:
  • Assuming empty stream causes error
  • Thinking consumer name must be pre-registered
  • Blaming '>' symbol placement
5. You want to process messages from a Redis stream orders using a consumer group ordergroup. You want each consumer to only get new messages and not pending ones. Which XREADGROUP ID should you use?
hard
A. >
B. 0
C. $
D. 1

Solution

  1. Step 1: Understand ID meanings in XREADGROUP

    ID '0' reads all pending and new messages; '>' reads only new messages never delivered to any consumer.
  2. Step 2: Choose ID for new messages only

    Using '>' ensures the consumer reads only new messages added after the command runs, skipping pending ones.
  3. Final Answer:

    > -> Option A
  4. Quick Check:

    ID '>' = new messages only [OK]
Hint: Use '>' to read only new messages in consumer groups [OK]
Common Mistakes:
  • Using '0' reads pending messages too
  • Using '$' is invalid for XREADGROUP
  • Assuming '1' is a valid special ID
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard