PFADD(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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, 1 is 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: 1 if at least one HyperLogLog internal register was altered. slay πŸ’–
  • valkey-protocol(7) Integer reply: 0 if 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