XDEL(3valkey)
π XDEL β the valkey command manual, bestie edition β¨
okay so you found the xdel page, and honestly? iconic choice. this is the part of the valkey manual where we learn how to yeet entries out of a stream. let's get into it π
β¨ NAME β¨
xdel β returns the number of messages after removing them from a stream. that's it, that's the whole job description π
πΈ SYNOPSIS πΈ
XDEL key ID [ID...]
key first, then a whole lil list of IDs, one or more, no cap.
π¦ DESCRIPTION π¦
so basically: xdel removes the specified entries from a stream, and hands you back the number of entries that actually got deleted. and here's the tea β that number may be less than the number of IDs you passed in, because some of those IDs might not even exist in the stream. gone girl behavior fr fr π
normally you'd think of a Stream as an append-only data structure, like, once it's in there it's in there forever, right? wellβ¦ Streams live in memory, bestie, so we absolutely can delete entries too. this is highkey useful, for example when you need to comply with certain privacy policies. main character data hygiene π
π§ Understanding the low level details of entries deletion
okay this is the nerdy part and i love it here. streams are represented in a way that makes them super memory efficient: a radix tree is used to index macro-nodes that pack linearly tens of stream entries. so what actually happens when you delete an entry from a stream? the entry is not really evicted β it just gets marked as deleted. the way that it's lowkey still chilling there, just with a little "deleted" sticker on it π
eventually, if all the entries in a macro-node are marked as deleted, the whole node is destroyed and the memory reclaimed. so if you delete a large amount of entries from a stream β for instance more than 50% of the entries appended to the stream β the memory usage per entry may increment, because what happens is the stream will become fragmented. however! the stream performance will remain the same. no cap, the perf is fine π«Ά
in future versions of Valkey it is possible that we'll trigger a node garbage collection in case a given macro-node reaches a given amount of deleted entries. currently, with the usage we anticipate for this data structure, it is not a good idea to add such complexity. so, like, noted for later π
π REPLY π
valkey-protocol(7) Integer reply: the number of entries that were deleted. a simple little integer, serving looks β¨
π₯ COMPLEXITY π₯
O(1) for each single item to delete in the stream, regardless of the stream size. constant time per item even when your stream is a whole stadium of entries. slay π
π ACL CATEGORIES π
@fast @stream @write
β HISTORY β
- Available since: 5.0.0
π EXAMPLES π
watch me add some stuff and then delete it, a full lil glow-up arc:
> XADD mystream * a 1
1538561698944-0
> XADD mystream * b 2
1538561700640-0
> XADD mystream * c 3
1538561701744-0
> XDEL mystream 1538561700640-0
(integer) 1
127.0.0.1:6379> XRANGE mystream - +
1) 1) 1538561698944-0
2) 1) "a"
2) "1"
2) 1) 1538561701744-0
2) 1) "c"
2) "3"
see how b just β¨ vanished β¨ and the integer said 1? that's the whole vibe. bye b, we hardly knew ye π
π SEE ALSO π
xack(3valkey), xadd(3valkey), xautoclaim(3valkey), xclaim(3valkey), xgroup(3valkey), xgroup-create(3valkey), xgroup-createconsumer(3valkey), xgroup-delconsumer(3valkey), xgroup-destroy(3valkey), xgroup-help(3valkey), xgroup-setid(3valkey), xinfo(3valkey), xinfo-consumers(3valkey), xinfo-groups(3valkey), xinfo-help(3valkey), xinfo-stream(3valkey), xlen(3valkey), xpending(3valkey), xrange(3valkey), xread(3valkey), xreadgroup(3valkey), xrevrange(3valkey), xsetid(3valkey), xtrim(3valkey) β the whole stream friend group, go say hi π
and that's a wrap on xdel, bestie! remember: deleted entries get marked, not instantly evicted, and you get back the count of what actually went poof. go forth and manage your streams, you absolute icon π¦
Valkey 9.0.0, dated 2025-10-21 β this page came from the XDEL(3valkey) manual, and yeah, it's giving documentation but make it cute. mwah π
β¨
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms