Bird
Raised Fist0
Redisquery~10 mins

XACK for acknowledging messages in Redis - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - XACK for acknowledging messages
Consumer reads message from stream
↓
Process message
↓
Send XACK command with stream, group, message ID
↓
Redis marks message as acknowledged
↓
Message removed from pending list
↓
Consumer can receive next message
The consumer reads a message, processes it, then sends XACK to Redis to mark it acknowledged, removing it from the pending list.
Execution Sample
Redis
XACK mystream mygroup 1609459200000-0
Acknowledges the message with ID 1609459200000-0 in group 'mygroup' on stream 'mystream'.
Execution Table
StepActionInputRedis ResponseEffect
1Consumer reads messageRead message ID 1609459200000-0Message deliveredMessage moved to pending list
2Consumer processes messageProcess message dataN/AMessage still pending
3Consumer sends XACKXACK mystream mygroup 1609459200000-01Message removed from pending list
4Consumer ready for next messageN/ANext message availableConsumer can read next message
💡 Message acknowledged and removed from pending list, so no longer pending.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
pending_listemptycontains 1609459200000-0contains 1609459200000-0emptyempty
message_statusunreadpendingprocessingacknowledgedacknowledged
Key Moments - 2 Insights
Why does the message stay in the pending list after reading but before XACK?
Because reading a message moves it to the pending list until the consumer confirms processing by sending XACK (see execution_table step 1 and 2).
What happens if the consumer never sends XACK?
The message remains in the pending list and can be claimed by other consumers later (not shown here but implied by step 3 importance).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Redis response when XACK is sent?
A"1"
B"Message delivered"
C"Next message available"
D"N/A"
💡 Hint
Check execution_table row 3 under Redis Response.
At which step does the message get removed from the pending list?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the Effect column in execution_table rows.
If the consumer processes the message but never sends XACK, what happens to the message_status variable after Step 3?
A"acknowledged"
B"processing"
C"pending"
D"unread"
💡 Hint
Refer to variable_tracker for message_status changes.
Concept Snapshot
XACK command acknowledges a message in a Redis stream consumer group.
Syntax: XACK <stream> <group> <message-id>
Marks message as processed, removing it from the pending list.
Without XACK, message stays pending and can be re-delivered.
Used after consumer processes the message successfully.
Full Transcript
In Redis streams, when a consumer reads a message, it moves to a pending list. The consumer must send the XACK command with the stream name, group name, and message ID to acknowledge processing. This removes the message from the pending list, so Redis knows it was handled. If the consumer does not send XACK, the message remains pending and can be delivered again. The execution flow shows reading the message, processing it, sending XACK, and then the message is removed from pending. Variables track the message status and pending list contents step-by-step.

Practice

(1/5)
1. What is the primary purpose of the XACK command in Redis streams?
easy
A. To delete a stream
B. To add a new message to a stream
C. To acknowledge that a message has been processed by a consumer
D. To create a new consumer group

Solution

  1. Step 1: Understand the role of XACK

    XACK is used in Redis streams to mark messages as processed by a consumer in a consumer group.
  2. Step 2: Differentiate from other commands

    Adding messages uses XADD, deleting streams uses DEL, and creating groups uses XGROUP. XACK specifically acknowledges messages.
  3. Final Answer:

    To acknowledge that a message has been processed by a consumer -> Option C
  4. Quick Check:

    XACK purpose = acknowledge processed message [OK]
Hint: XACK always marks messages as processed in consumer groups [OK]
Common Mistakes:
  • Confusing XACK with XADD or XGROUP
  • Thinking XACK deletes messages
  • Assuming XACK creates consumer groups
2. Which of the following is the correct syntax to acknowledge a message with ID 1526985058136-0 in consumer group group1 on stream mystream?
easy
A. XACK 1526985058136-0 mystream group1
B. XACK mystream group1 1526985058136-0
C. XACK mystream 1526985058136-0 group1
D. XACK group1 mystream 1526985058136-0

Solution

  1. Step 1: Recall XACK command syntax

    The syntax is: XACK <stream> <group> <ID> [ID ...].
  2. Step 2: Match the given IDs and names

    Stream is mystream, group is group1, and message ID is 1526985058136-0, so the correct order is XACK mystream group1 1526985058136-0.
  3. Final Answer:

    XACK mystream group1 1526985058136-0 -> Option B
  4. Quick Check:

    XACK syntax = XACK stream group ID [OK]
Hint: XACK order: stream, group, then message IDs [OK]
Common Mistakes:
  • Swapping group and stream names
  • Placing message ID before stream or group
  • Using incorrect command order
3. Given the following Redis commands executed in order:
XGROUP CREATE mystream group1 $ MKSTREAM
XADD mystream 1609459200000-0 field1 value1
XREADGROUP GROUP group1 consumer1 COUNT 1 STREAMS mystream >
XACK mystream group1 1609459200000-0
What will be the result of the XACK command?
medium
A. 1
B. 0
C. An error because the message ID does not exist
D. An error because the consumer group does not exist

Solution

  1. Step 1: Analyze the commands and message ID

    The group 'group1' is created on 'mystream'. A message is added with XADD, then read by consumer1. The XACK acknowledges message ID 1609459200000-0.
  2. Step 2: Confirm message ID existence and acknowledgment

    XADD adds the message with the specified ID 1609459200000-0. The XREADGROUP delivers it to consumer1's pending entries. XACK then acknowledges it and returns 1, the count of acknowledged messages.
  3. Final Answer:

    1 -> Option A
  4. Quick Check:

    XACK returns count of acknowledged messages = 1 [OK]
Hint: XACK returns number of messages acknowledged [OK]
Common Mistakes:
  • Assuming XACK returns message content
  • Thinking XACK errors if message ID is valid
  • Confusing XACK with XREADGROUP output
4. You run the command XACK mystream group1 1609459200000-0 but get an error: (error) NOGROUP No such consumer group 'group1' for stream 'mystream'. What is the most likely cause?
medium
A. The stream 'mystream' does not exist
B. The message ID is invalid
C. The XACK command syntax is incorrect
D. The consumer group 'group1' was not created on 'mystream'

Solution

  1. Step 1: Interpret the error message

    The error says no such consumer group 'group1' for stream 'mystream', meaning the group does not exist on that stream.
  2. Step 2: Identify the cause

    Either the group was never created or was created on a different stream. The stream existing or message ID validity does not cause this error.
  3. Final Answer:

    The consumer group 'group1' was not created on 'mystream' -> Option D
  4. Quick Check:

    Error NOGROUP means missing consumer group [OK]
Hint: NOGROUP error means consumer group missing on stream [OK]
Common Mistakes:
  • Assuming stream absence causes NOGROUP error
  • Blaming message ID format
  • Misreading error as syntax issue
5. You have a Redis stream orders with a consumer group processors. You want to acknowledge multiple messages with IDs 1609459200000-0, 1609459200001-0, and 1609459200002-0 in one command. Which command correctly does this?
hard
A. XACK orders processors 1609459200000-0 1609459200001-0 1609459200002-0
B. XACK orders processors [1609459200000-0, 1609459200001-0, 1609459200002-0]
C. XACK orders processors "1609459200000-0 1609459200001-0 1609459200002-0"
D. XACK orders processors {1609459200000-0,1609459200001-0,1609459200002-0}

Solution

  1. Step 1: Recall XACK syntax for multiple IDs

    XACK accepts multiple message IDs separated by spaces without brackets or quotes.
  2. Step 2: Evaluate options

    XACK orders processors 1609459200000-0 1609459200001-0 1609459200002-0 lists IDs separated by spaces correctly. Options B, C, and D use brackets, quotes, or braces which are invalid syntax.
  3. Final Answer:

    XACK orders processors 1609459200000-0 1609459200001-0 1609459200002-0 -> Option A
  4. Quick Check:

    Multiple IDs in XACK = space-separated list [OK]
Hint: List multiple IDs space-separated in XACK command [OK]
Common Mistakes:
  • Using brackets or quotes around IDs
  • Separating IDs with commas
  • Passing IDs as a single string
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