PFCOUNT
PFCOUNT key [key ...]
- Group
- HyperLogLog
- Complexity
- O(1) for one key, O(N) for N keys
- Arity
- -2 (at least 2 words, counting the command name)
- Flags
- read-only
- Keys
- first 1, last final argument, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
PFCOUNT returns the estimated number of distinct elements added to the
HyperLogLog at key. With several keys it returns the estimate for their
union, without changing any of them. A missing key counts as an empty
HyperLogLog.
With a single key, PFCOUNT can count as a modification of the key: a
WATCH on it sees the key as changed.
In a cluster, all keys must hash to the same slot.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Always | Integer: the estimated distinct count | Integer |
The errors are those of PFADD: a WRONGTYPE error for a
string that is not a HyperLogLog or a key of another type, and INVALIDOBJ
for damaged data.
Examples
Section titled “Examples”127.0.0.1:6379> PFADD day:1 alice bob carol(integer) 1127.0.0.1:6379> PFADD day:2 carol dave(integer) 1127.0.0.1:6379> PFCOUNT day:1(integer) 3127.0.0.1:6379> PFCOUNT day:1 day:2(integer) 4127.0.0.1:6379> PFCOUNT missing(integer) 0Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.