HSTRLEN(3valkey)
β¨ HSTRLEN π
okay bestie so this is a page from the Valkey Command Manual, section 3valkey β yes the whole thing lives in the manual, and today we're learning about hstrlen. it's giving "how long is this field's value actually" energy and honestly? iconic.
π NAME π
hstrlen β Returns the length of the value of a field. that's it. that's the whole job. no cap.
πΈ SYNOPSIS πΈ
HSTRLEN key field
just two little arguments, two little besties, one very chill command π«Ά
π¦ DESCRIPTION π¦
so basically: HSTRLEN returns the string length of the value that's associated with field inside the hash stored at key. that's the vibe.
and if the key doesn't exist, or the field doesn't exist? you get 0. zero. nothing. empty. the void returns a number and the number is zero π
π REPLY π
valkey-protocol(7) Integer reply β literally just the string length of the value associated with the field, or zero when the field isn't present in the hash or the key doesn't exist at all. both of those sad little scenarios give you 0. periodt.
β COMPLEXITY β
constant time bestie, it does not care how big your hash is, it is NOT stressing β¨
π ACL CATEGORIES π
@fast@hash@read
three little tags, all of them slay π
πΈ HISTORY πΈ
- Available since:
3.2.0β a classic, honestly. vintage but make it fast π§
π₯ EXAMPLES π₯
watch this, it's so satisfying:
127.0.0.1:6379> HSET myhash f1 HelloWorld f2 99 f3 -256
(integer) 3
127.0.0.1:6379> HSTRLEN myhash f1
(integer) 10
127.0.0.1:6379> HSTRLEN myhash f2
(integer) 2
127.0.0.1:6379> HSTRLEN myhash f3
(integer) 4
ok so HelloWorld is 10 characters, 99 is 2, and -256 is 4 β because the minus sign is a character too, bestie. the way it counts the - as a whole entire characterβ¦ not me being obsessed with string semantics π
π SEE ALSO π
the whole hash girlie squad, go read them too:
hdel(3valkey)hexists(3valkey)hexpire(3valkey)hexpireat(3valkey)hexpiretime(3valkey)hget(3valkey)hgetall(3valkey)hgetex(3valkey)hincrby(3valkey)hincrbyfloat(3valkey)hkeys(3valkey)hlen(3valkey)hmget(3valkey)hmset(3valkey)hpersist(3valkey)hpexpire(3valkey)hpexpireat(3valkey)hpexpiretime(3valkey)hpttl(3valkey)hrandfield(3valkey)hscan(3valkey)hset(3valkey)hsetex(3valkey)hsetnx(3valkey)httl(3valkey)hvals(3valkey)
lowkey a reminder: HSTRLEN only cares about the length of the string value. it doesn't care if the value looks like a number, it's still a string and it's still getting counted. iykyk π
okay that's the whole page bestie, we ate and left no crumbs π this one's from version 9.0.0, dated 2025-10-21, and that's the HSTRLEN(3valkey) manual page β go forth and count your strings, 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