# Acknowledge and delete a single entryresult = redis.xackdel("mystream", "mygroup", "1638360173533-0")print(result) # List of results for each ID
# Acknowledge and delete multiple entriesresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", "1638360173533-1", "1638360173533-2")print(result) # List of results for each ID
# Keep consumer group references when deleting entries# Useful when you want to delete entries but maintain group trackingresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", "1638360173533-1", option="KEEPREF")print(result) # List of results for each ID
# Delete consumer group references along with entries# Useful for complete cleanup of processed messagesresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", "1638360173533-1", option="DELREF")print(result) # List of results for each ID
# Only acknowledge messages without deleting them# Useful when you want to mark as processed but keep for audit/debuggingresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", option="ACKED")print(result) # List of results for each ID# Entry remains in stream but is acknowledged
# Create a consumer groupredis.xgroup_create("orders", "processors", "0", mkstream=True)# Add some orders to the streamredis.xadd("orders", "*", {"order_id": "123", "status": "pending"})redis.xadd("orders", "*", {"order_id": "124", "status": "pending"})# Read messages as a consumermessages = redis.xreadgroup( "processors", "consumer1", {"orders": ">"}, count=2)# Process messages and acknowledge + delete themfor stream_name, entries in messages: for entry_id, fields in entries: # Process the order... print(f"Processing order {fields['order_id']}") # Acknowledge and delete the entry (default behavior) redis.xackdel("orders", "processors", entry_id) # Or use DELREF for complete cleanup # redis.xackdel("orders", "processors", entry_id, option="DELREF")
# Read pending messagespending = redis.xreadgroup( "tasks", "worker1", {"task-queue": ">"}, count=10)if pending: stream_name, entries = pending[0] processed_ids = [] # Process each task for entry_id, fields in entries: try: # Process task... print(f"Processing task {entry_id}") processed_ids.append(entry_id) except Exception as error: print(f"Failed to process {entry_id}: {error}") # Acknowledge and delete all successfully processed tasks # Using DELREF to completely remove references if processed_ids: result = redis.xackdel("task-queue", "tasks", *processed_ids, option="DELREF") print(f"Results: {result}") # List of results for each ID
# Process messages but keep them for audit/debugging purposesmessages = redis.xreadgroup( "audit", "auditor1", {"events": ">"}, count=5)for stream_name, entries in messages: entry_ids = [entry_id for entry_id, _ in entries] # Process and acknowledge but don't delete for entry_id, fields in entries: # Audit the event... print(f"Auditing event {fields}") # Acknowledge without deleting (keep for audit trail) result = redis.xackdel("events", "audit", *entry_ids, option="ACKED") print(f"Acknowledged {len(result)} events (kept in stream)")
Stream
XACKDEL
Acknowledge and delete stream entries atomically.
The XACKDEL command acknowledges and deletes stream entries atomically in a single operation. This is useful for consumer groups where you want to acknowledge message processing and remove the entries from the stream simultaneously.
A list of integers indicating the result for each ID in the same order as provided.
# Acknowledge and delete a single entryresult = redis.xackdel("mystream", "mygroup", "1638360173533-0")print(result) # List of results for each ID
# Acknowledge and delete multiple entriesresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", "1638360173533-1", "1638360173533-2")print(result) # List of results for each ID
# Keep consumer group references when deleting entries# Useful when you want to delete entries but maintain group trackingresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", "1638360173533-1", option="KEEPREF")print(result) # List of results for each ID
# Delete consumer group references along with entries# Useful for complete cleanup of processed messagesresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", "1638360173533-1", option="DELREF")print(result) # List of results for each ID
# Only acknowledge messages without deleting them# Useful when you want to mark as processed but keep for audit/debuggingresult = redis.xackdel( "mystream", "mygroup", "1638360173533-0", option="ACKED")print(result) # List of results for each ID# Entry remains in stream but is acknowledged
# Create a consumer groupredis.xgroup_create("orders", "processors", "0", mkstream=True)# Add some orders to the streamredis.xadd("orders", "*", {"order_id": "123", "status": "pending"})redis.xadd("orders", "*", {"order_id": "124", "status": "pending"})# Read messages as a consumermessages = redis.xreadgroup( "processors", "consumer1", {"orders": ">"}, count=2)# Process messages and acknowledge + delete themfor stream_name, entries in messages: for entry_id, fields in entries: # Process the order... print(f"Processing order {fields['order_id']}") # Acknowledge and delete the entry (default behavior) redis.xackdel("orders", "processors", entry_id) # Or use DELREF for complete cleanup # redis.xackdel("orders", "processors", entry_id, option="DELREF")
# Read pending messagespending = redis.xreadgroup( "tasks", "worker1", {"task-queue": ">"}, count=10)if pending: stream_name, entries = pending[0] processed_ids = [] # Process each task for entry_id, fields in entries: try: # Process task... print(f"Processing task {entry_id}") processed_ids.append(entry_id) except Exception as error: print(f"Failed to process {entry_id}: {error}") # Acknowledge and delete all successfully processed tasks # Using DELREF to completely remove references if processed_ids: result = redis.xackdel("task-queue", "tasks", *processed_ids, option="DELREF") print(f"Results: {result}") # List of results for each ID
# Process messages but keep them for audit/debugging purposesmessages = redis.xreadgroup( "audit", "auditor1", {"events": ">"}, count=5)for stream_name, entries in messages: entry_ids = [entry_id for entry_id, _ in entries] # Process and acknowledge but don't delete for entry_id, fields in entries: # Audit the event... print(f"Auditing event {fields}") # Acknowledge without deleting (keep for audit trail) result = redis.xackdel("events", "audit", *entry_ids, option="ACKED") print(f"Acknowledged {len(result)} events (kept in stream)")
# Acknowledge the messageredis.xack("mystream", "mygroup", "123-0")# Then delete itredis.xdel("mystream", "123-0")
With XACKDEL (single atomic operation):
# Acknowledge and delete in one operation (default)redis.xackdel("mystream", "mygroup", "123-0")# With options for fine-grained controlredis.xackdel("mystream", "mygroup", "123-0", option="DELREF") # Complete cleanupredis.xackdel("mystream", "mygroup", "123-0", option="ACKED") # Acknowledge only
This command is available in Redis 8.2.0 and later. It combines XACK and XDEL into a single atomic operation, which is more efficient and ensures consistency.