XLEN(3valkey)
β¨ XLEN β¨
okay bestie, this is XLEN, a little command from the valkey manual, and it's literally the simplest glow-up in the whole stream family π
πΈ NAME πΈ
xlen β bestie, it counts the messages chillin' in a stream. that's it. that's the whole job π
π SYNOPSIS π
XLEN key
one argument. one key. iconic, no notes β¨
π¦ DESCRIPTION π¦
okay so XLEN returns the number of entries inside a stream. periodt.
if the key you handed it doesn't exist, the command returns zero, like the stream was empty all along. cute, right? π but here's the plot twist β and listen closely because this is the part that gets people:
unlike other Valkey types, zero-length streams are possible. so if you actually need to know whether a key exists or not, you gotta callTYPEorEXISTS. don't just trust the zero. the zero can lie to you fr fr π
and another thing, bestie β streams do NOT auto-delete just because they got no entries left inside. like, even after an XDEL call wipes everything out, the stream is still there, still standing, because it might have consumer groups attached to it and those groups have feelings. main character energy honestly. the stream stays. π
π REPLY π
valkey-protocol(7) Integer reply: the number of entries of the stream at key. just a number. a whole number. gorgeous. β
π COMPLEXITY π
constant time, baby!! it does not care how big your stream is, it just knows. that's the confidence we're talking about π β¨
π ACL CATEGORIES π
@fast@read@stream
π HISTORY π
- Available since:
5.0.0
a legend since day one, no cap π«Ά
πΈ EXAMPLES πΈ
okay watch this, we're gonna build a tiny stream and then count it:
127.0.0.1:6379> XADD mystream * item 1
"1714701492011-0"
127.0.0.1:6379> XADD mystream * item 2
"1714701492021-0"
127.0.0.1:6379> XADD mystream * item 3
"1714701492031-0"
127.0.0.1:6379> XLEN mystream
(integer) 3
three adds, three entries, and XLEN said (integer) 3. we ate that fr π₯
π§ SEE ALSO π§
xack(3valkey)xadd(3valkey)xautoclaim(3valkey)xclaim(3valkey)xdel(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)xpending(3valkey)xrange(3valkey)xread(3valkey)xreadgroup(3valkey)xrevrange(3valkey)xsetid(3valkey)xtrim(3valkey)
the whole stream squad, all linked, all iconic π
okay that's the whole page bestie, and before you go β this one's from version 9.0.0, dated 2025-10-21 π go forth and count your messages, you absolute legend πβ¨π¦
π¦ 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