0
0
RedisHow-ToBeginner · 3 min read

How to Use XACK Command in Redis Streams

Use the XACK command in Redis to acknowledge that a consumer has processed one or more messages from a stream in a consumer group. This removes the messages from the pending entries list, signaling they are handled and won't be delivered again.
📐

Syntax

The XACK command syntax is:

  • XACK <stream> <group> <id> [id ...]

Here:

  • stream: The name of the Redis stream.
  • group: The consumer group name.
  • id: One or more message IDs to acknowledge.
redis
XACK mystream mygroup 1526985058136-0 1526985058137-0
💻

Example

This example shows how to acknowledge two messages with IDs 1526985058136-0 and 1526985058137-0 from the consumer group mygroup on the stream mystream.

redis
127.0.0.1:6379> XACK mystream mygroup 1526985058136-0 1526985058137-0
(integer) 2
Output
(integer) 2
⚠️

Common Pitfalls

Common mistakes when using XACK include:

  • Trying to acknowledge message IDs that do not exist or were never delivered to the group, which results in zero acknowledgments.
  • Using the wrong consumer group name or stream name, causing the command to acknowledge nothing.
  • Not acknowledging messages after processing, which causes them to remain in the pending entries list and may lead to duplicate processing.
redis
127.0.0.1:6379> XACK mystream wronggroup 1526985058136-0
(integer) 0

# Correct usage:
127.0.0.1:6379> XACK mystream mygroup 1526985058136-0
(integer) 1
Output
(integer) 0 (integer) 1
📊

Quick Reference

CommandDescription
XACK [id ...]Acknowledge one or more messages in a consumer group
ReturnsNumber of messages acknowledged
EffectRemoves messages from the pending entries list
Use caseConfirm message processing to avoid duplicates

Key Takeaways

Use XACK to confirm messages are processed and remove them from the pending list.
Always specify the correct stream, group, and message IDs to acknowledge.
Unacknowledged messages remain pending and may be delivered again.
XACK returns the count of messages successfully acknowledged.
Check for zero return value to detect wrong IDs or group names.