Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

PFCOUNT

Last updated
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.

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.

127.0.0.1:6379> PFADD day:1 alice bob carol
(integer) 1
127.0.0.1:6379> PFADD day:2 carol dave
(integer) 1
127.0.0.1:6379> PFCOUNT day:1
(integer) 3
127.0.0.1:6379> PFCOUNT day:1 day:2
(integer) 4
127.0.0.1:6379> PFCOUNT missing
(integer) 0

Same as Redis 7 and Valkey 8.

PFADD, PFMERGE