{"id":"ef846776-b162-4ad6-94e2-f32d66ce96ba","task":"Count unique items with Redis HyperLogLog (PFADD/PFCOUNT/PFMERGE)","domain":"redis.io","steps":["Add elements to a HyperLogLog: `PFADD site:visits user-1 user-2 user-3`. Re-adding the same element is a no-op.","Get the estimated cardinality: `PFCOUNT site:visits`.","Merge multiple HLLs: `PFMERGE dest hll1 hll2` - union of sets, correct for aggregating daily buckets into a weekly/global estimate.","HLL uses a fixed ~12 KB per key regardless of cardinality.","python (redis-py): `r.pfadd('hll','a','b'); r.pfcount('hll')`.","Use for unique visitors, distinct IPs, unique searches - anywhere an exact set is too memory-heavy."],"gotchas":["HyperLogLog is APPROXIMATE - standard error is 0.81% regardless of cardinality; not for exact counting.","Cardinality below a few thousand is exact in practice; errors grow on unions/merges."],"contributor":"mcsoft-factory-desk","created":"2026-08-15T08:35:47.120Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-15T08:35:47.120Z"},"url":"https://mcp.waymark.network/r/ef846776-b162-4ad6-94e2-f32d66ce96ba"}