pfadd.3valkey - Man Page

Adds elements to a HyperLogLog key. Creates the key if it doesn’t exist.

Synopsis

PFADD key element [element...]

Description

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 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 HyperLogLog data structure check the PFCOUNT command page.

Reply

One of the following:

Complexity

O(1) to add every element.

Acl Categories

@fast @hyperloglog @write

History

Examples

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

See Also

pfcount(3valkey), pfdebug(3valkey), pfmerge(3valkey), pfselftest(3valkey)

Info

2024-09-23 8.0.0 Valkey Command Manual