# PFMERGE

```json metadata
{
  "schema_version": 2,
  "title": "PFMERGE",
  "description": "Merges one or more HyperLogLog values into a single key.",
  "categories": ["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],
  "arguments": [{"display_text":"destkey","key_spec_index":0,"name":"destkey","type":"key"},{"display_text":"sourcekey","key_spec_index":1,"multiple":true,"name":"sourcekey","optional":true,"type":"key"}],
  "syntax_fmt": "PFMERGE destkey [sourcekey [sourcekey ...]]",
  "complexity": "O(N) to merge N HyperLogLogs, but with high constant times.",
  "group": "hyperloglog",
  "command_flags": ["write","denyoom"],
  "acl_categories": ["@write","@hyperloglog","@slow"],
  "since": "2.8.9",
  "arity": -2,
  "key_specs": [{"RW":true,"access":true,"begin_search":{"spec":{"index":1},"type":"index"},"find_keys":{"spec":{"keystep":1,"lastkey":0,"limit":0},"type":"range"},"insert":true},{"RO":true,"access":true,"begin_search":{"spec":{"index":2},"type":"index"},"find_keys":{"spec":{"keystep":1,"lastkey":-1,"limit":0},"type":"range"}}],
  "tableOfContents": {"sections":[{"id":"required-arguments","title":"Required arguments"},{"id":"optional-arguments","title":"Optional arguments"},{"id":"examples","title":"Examples"},{"id":"redis-software-and-redis-cloud-compatibility","title":"Redis Software and Redis Cloud compatibility"},{"id":"return-information","title":"Return information"}]}

,
  "codeExamples": []
}
```

> [!NOTE]
> This command's behavior varies in clustered Redis environments. See the [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations) page for more information.


Merge multiple HyperLogLog values into a unique value that will approximate
the cardinality of the union of the observed sets of the source HyperLogLog
structures.

The computed merged HyperLogLog is set to the destination variable, which is
created if it does not exist (defaulting to an empty HyperLogLog).

If the destination variable exists, it is treated as one of the source sets 
and its cardinality will be included in the cardinality of the computed
HyperLogLog.

## Required arguments

<details open><summary><code>destkey</code></summary>

The destination HyperLogLog key in which to store the merged result.

</details>

## Optional arguments

<details open><summary><code>sourcekey [sourcekey ...]</code></summary>

One or more source HyperLogLog keys to merge into `destkey`. `destkey` itself is also included in the merge.

</details>

## Examples


redis> PFADD hll1 foo bar zap a
(integer) 1
redis> PFADD hll2 a b c foo
(integer) 1
redis> PFMERGE hll3 hll1 hll2
OK
redis> PFCOUNT hll3
(integer) 6


## Redis Software and Redis Cloud compatibility

| Redis<br />Software | Redis<br />Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> |
|:----------------------|:-----------------|:------|
| <span title="Supported">&#x2705; Standard</span><br /><span title="Supported"><nobr>&#x2705; Active-Active</nobr></span> | <span title="Supported">&#x2705; Standard</span><br /><span title="Supported"><nobr>&#x2705; Active-Active</nobr></span> |  |

## Return information

**RESP2:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.

**RESP3:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.



