PFADD
PFADD key [element [element ...]]
- Group
- HyperLogLog
- Complexity
- O(1) per element
- Arity
- -2 (at least 2 words, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
PFADD adds elements to the HyperLogLog at key, creating it if needed. A
HyperLogLog estimates how many distinct elements it has seen, using a small,
fixed amount of memory (at most about 12 KB) whatever the count, with a
typical error below 1%. Use it to count unique visitors, search terms or
events when an exact set would be too large.
Called with no elements, PFADD only creates an empty HyperLogLog if the key
does not exist. HyperLogLogs are stored as strings, so TYPE
reports string. The key keeps its time to live.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| The estimate changed, or the key was created | Integer 1 |
Integer 1 |
| Nothing changed | Integer 0 |
Integer 0 |
Errors:
WRONGTYPE Key is not a valid HyperLogLog string value.when the key holds a string that is not a HyperLogLog.INVALIDOBJ Corrupted HLL object detectedwhen the HyperLogLog data is damaged.WRONGTYPE Operation against a key holding the wrong kind of valuewhen the key holds another type.
Examples
Section titled “Examples”127.0.0.1:6379> PFADD visitors alice bob carol(integer) 1127.0.0.1:6379> PFADD visitors alice(integer) 0127.0.0.1:6379> PFCOUNT visitors(integer) 3Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8, and the stored format is the same: a HyperLogLog moved between HotKV and Redis with DUMP and RESTORE keeps working.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.