HyperLogLog API

Purely functional interface for the HyperLogLog API, a probabilistic data structure for estimating the cardinality of a set using a small, fixed amount of memory.

HyperLogLog Commands usage

Once you have acquired a connection you can start using it:

commandsApi.use { redis => // HyperLogLogCommands[IO, String, String]
  for {
    _     <- redis.pfAdd("visitors", "alice", "bob", "alice") // PFADD — duplicates are ignored
    count <- redis.pfCount("visitors")                        // PFCOUNT — approximate cardinality (~2)
    _     <- redis.pfAdd("today", "carol")
    _     <- redis.pfMerge("all-visitors", "visitors", "today") // PFMERGE — union into a new key
  } yield count
}

pfCount returns an estimate (with a standard error of ~0.81%), not an exact count — that is the trade-off that lets a HyperLogLog track huge sets in a constant ~12 KB.