Skip to main content
Use PFADD to add elements to a HyperLogLog. A HyperLogLog estimates how many distinct items it has seen while using a small, fixed amount of memory (at most about 12 KB) no matter how many elements pass through it. That is the trade it makes: individual elements are not stored, so they cannot be listed, checked for membership, or removed, and the cardinality that comes back from PFCOUNT is an approximation with a standard error of about 0.81%. The key is created on first use, and the reply is 1 when the internal registers changed as a result of the call, which is a hint that at least one element was new, and 0 when they did not. Calling PFADD with no elements creates an empty HyperLogLog if the key does not exist yet. Use it for counts where the exact number does not matter, such as unique visitors per page or per day, and a set for cases where you must be able to look elements up.

Syntax

Arguments

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.