# PFCOUNT

> Return the approximate number of distinct elements in one or more HyperLogLogs.

URL: https://docs.hotkv.com/commands/pfcount/

```
PFCOUNT key [key ...]
```

- Group: HyperLogLog
- Complexity: O(1) for one key, O(N) for N keys
- 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](https://docs.hotkv.com/commands/watch/index.md) on it sees the key as changed.

In a cluster, all keys must hash to the same slot.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Integer: the estimated distinct count | Integer |

The errors are those of [PFADD](https://docs.hotkv.com/commands/pfadd/index.md): a `WRONGTYPE` error for a
string that is not a HyperLogLog or a key of another type, and `INVALIDOBJ`
for damaged data.

## Examples

```
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
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[PFADD](https://docs.hotkv.com/commands/pfadd/index.md), [PFMERGE](https://docs.hotkv.com/commands/pfmerge/index.md)