# PFMERGE

> Merge HyperLogLogs into a destination HyperLogLog.

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

```
PFMERGE destkey [sourcekey [sourcekey ...]]
```

- Group: HyperLogLog
- Complexity: O(N) for N source keys
- HotKV Cloud: all plans
- On-Premise: no license needed

`PFMERGE` combines the source HyperLogLogs into `destkey`, so that its
estimate covers every element seen by any of them. If `destkey` already holds
a HyperLogLog, it is part of the union too; otherwise it is created. Missing
sources are skipped. With no sources, `PFMERGE` just makes sure `destkey`
exists as a HyperLogLog. The destination keeps its time to live.

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

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Simple string `OK` | Simple string `OK` |

The errors are those of [PFADD](https://docs.hotkv.com/commands/pfadd/index.md), for the destination or any
source.

## 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> PFMERGE week day:1 day:2
OK
127.0.0.1:6379> PFCOUNT week
(integer) 4
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

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