# PFADD

```json metadata
{
  "schema_version": 2,
  "title": "PFADD",
  "description": "Adds elements to a HyperLogLog key. Creates the key if it doesn't exist.",
  "categories": ["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],
  "arguments": [{"display_text":"key","key_spec_index":0,"name":"key","type":"key"},{"display_text":"element","multiple":true,"name":"element","optional":true,"type":"string"}],
  "syntax_fmt": "PFADD key [element [element ...]]",
  "complexity": "O(1) to add every element.",
  "group": "hyperloglog",
  "command_flags": ["write","denyoom","fast"],
  "acl_categories": ["@write","@hyperloglog","@fast"],
  "since": "2.8.9",
  "arity": -2,
  "key_specs": [{"RW":true,"begin_search":{"spec":{"index":1},"type":"index"},"find_keys":{"spec":{"keystep":1,"lastkey":0,"limit":0},"type":"range"},"insert":true}],
  "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": []
}
```

Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.

As a side effect of this command the HyperLogLog internals may be updated to reflect a different estimation of the number of unique items added so far (the cardinality of the set).

If the approximated cardinality estimated by the HyperLogLog changed after executing the command, `PFADD` returns 1, otherwise 0 is returned. The command automatically creates an empty HyperLogLog structure (that is, a Redis String of a specified length and with a given encoding) if the specified key does not exist.

To call the command without elements but just the variable name is valid, this will result into no operation performed if the variable already exists, or just the creation of the data structure if the key does not exist (in the latter case 1 is returned).

For an introduction to the HyperLogLog data structure check its  [data structure page](https://redis.io/docs/latest/develop/data-types/probabilistic/hyperloglogs) and the [`PFCOUNT`](https://redis.io/docs/latest/commands/pfcount) command page.

## Required arguments

<details open><summary><code>key</code></summary>

The name of the HyperLogLog key.

</details>

## Optional arguments

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

One or more elements to add to the HyperLogLog. With no elements, the command only creates the key if it does not already exist.

</details>

## Examples


redis> PFADD hll a b c d e f g
(integer) 1
redis> PFCOUNT hll
(integer) 7


## 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:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if at least one HyperLogLog internal register was altered.
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no HyperLogLog internal registers were altered.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if at least one HyperLogLog internal register was altered.
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no HyperLogLog internal registers were altered.



