PFADD(3valkey)
π PFADD β bestie, it's giving HyperLogLog glow-up β¨
okay so this is PFADD from the Valkey Command Manual (that's the 3valkey manual section, bestie, iykyk) β and it's literally the cutest little command for stuffing elements into a HyperLogLog key. Let's get into it π«Ά
β¨ NAME β¨
pfadd β adds elements to a HyperLogLog key. and like, it creates the key if it doesn't exist too, because it's generous like that π
πΈ SYNOPSIS πΈ
PFADD key element [element...]
π¦ DESCRIPTION π¦
So basically? It adds all the element arguments to the HyperLogLog data structure that's stored at the variable name you passed as the first argument. all of them. every single one. no cap π
and as a little side effect of this command, the HyperLogLog internals may get updated to reflect a different estimation of the number of unique items added so far β that's the cardinality of the set, for those of you keeping score at home β¨
Here's the vibe check on the return value: if the approximated cardinality estimated by the HyperLogLog changed after running the command, PFADD returns 1. Otherwise it returns 0. periodt π
and if the key you specified doesn't exist? It automatically creates an empty HyperLogLog structure for you β that's, like, a String of a specified length and with a given encoding. it just shows up. main character energy π
You can also call the command with no elements at all, just the variable name β that's totally valid! And it will result in:
- no operation performed if the variable already exists, or
- just the creation of the data structure if the key does not exist (and in that latter case,
1is returned π)
wanna actually understand what a HyperLogLog is, bestie? go check the valkey-pfcount(7) PFCOUNT command page, it's got the whole introduction π§
π REPLY π
One of the following, bestie:
valkey-protocol(7)Integer reply:1if at least one HyperLogLog internal register was altered. slay πvalkey-protocol(7)Integer reply:0if no HyperLogLog internal registers were altered. nothing moved. it's giving stillness π
π₯ COMPLEXITY π₯
O(1) to add every element. yeah. constant time. we love efficiency in this house β¨
π ACL CATEGORIES π
@fast @hyperloglog @write
π HISTORY π
- Available since:
2.8.9β an icon from the very beginning π
β EXAMPLES β
127.0.0.1:6379> PFADD hll a b c d e f g
(integer) 1
127.0.0.1:6379> PFCOUNT hll
(integer) 7
look at that. seven elements in, seven counted out. we ate that fr fr π½οΈβ¨
π SEE ALSO π
pfcount(3valkey), pfdebug(3valkey), pfmerge(3valkey), pfselftest(3valkey)
and that's the whole page, bestie π«Ά this was written for Valkey 9.0.0, dated 2025-10-21, and it lives at PFADD(3valkey). go forth and add elements. you're gonna do amazing ππΈπ¦
π¦ 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