Back to Redis

XDELEX

content/commands/xdelex.md

latest3.9 KB
Original Source

Deletes one or multiple entries from the stream at the specified key.

XDELEX is an extension of the Redis Streams [XDEL]({{< relref "/commands/xdel" >}}) command that provides more control over how message entries are deleted concerning consumer groups.

Required arguments

<details open> <summary><code>key</code></summary>

The name of the stream key.

</details> <details open> <summary><code>IDS numids id [id ...]</code></summary>

The IDS block specifying which entries to delete:

  • numids: The number of IDs that follow
  • id [id ...]: One or more stream entry IDs to delete

Note: The IDS block can be at any position in the command, same as other commands.

</details>

Optional arguments

<details open> <summary><code>KEEPREF | DELREF | ACKED</code></summary>

Specifies how to handle consumer group references when deleting entries. Available since Redis 8.2. If no option is specified, KEEPREF is used by default:

  • KEEPREF (default): Deletes the specified entries from the stream, but preserves existing references to these entries in all consumer groups' PEL (Pending Entries List). This behavior is similar to [XDEL]({{< relref "/commands/xdel" >}}).
  • DELREF: Deletes the specified entries from the stream and also removes all references to these entries from all consumer groups' pending entry lists, effectively cleaning up all traces of the messages. If an entry ID is not in the stream, but there are dangling references, XDELEX with DELREF would still remove all those references.
  • ACKED: Only deletes entries that were read and acknowledged by all consumer groups.
</details>

The command provides fine-grained control over stream entry deletion, particularly useful when working with consumer groups where you need to manage pending entry references carefully.

Examples

{{% redis-cli %}} XADD mystream * field1 value1 XADD mystream * field2 value2 XADD mystream * field3 value3 XRANGE mystream - + XDELEX mystream KEEPREF IDS 2 1526919030474-55 1526919030474-56 XRANGE mystream - + {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="xdelex-return-info" tab1="RESP2" tab2="RESP3" >}}

One of the following:

  • [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}): -1 for each requested ID when the given key does not exist.
  • Array reply: For each ID:
    • Integer reply: -1 if no such ID exists in the provided stream key.
    • Integer reply: 1 if the entry was deleted from the stream.
    • Integer reply: 2 if the entry was not deleted and there are still existing references (ACKED option); also, if there are no consumer groups.

-tab-sep-

One of the following:

  • [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}): -1 for each requested ID when the given key does not exist.
  • Array reply: For each ID:
    • Integer reply: -1 if no such ID exists in the provided stream key.
    • Integer reply: 1 if the entry was deleted from the stream.
    • Integer reply: 2 if the entry was not deleted and there are still existing references (ACKED option); also, if there are no consumer groups.

{{< /multitabs >}}