Ferricstore.Commands.HyperLogLog (ferricstore v0.3.3)

Copy Markdown View Source

Handles Redis HyperLogLog commands: PFADD, PFCOUNT, PFMERGE.

Each handler takes the uppercased command name, a list of string arguments, and an injected store map. Returns plain Elixir terms -- the connection layer handles RESP encoding.

HyperLogLog sketches are stored as plain 16,384-byte binary values in the store with no expiry (expire_at_ms = 0). They are transparent to the store layer -- just another binary blob keyed by a string.

Supported commands

  • PFADD key element [element ...] -- adds elements to the HLL sketch at key, creating it if absent. Returns 1 if the sketch was modified, 0 if not.
  • PFCOUNT key [key ...] -- returns the estimated cardinality. For a single key, returns the estimate from that sketch. For multiple keys, merges sketches in memory (without writing) and returns the combined estimate. Non-existent keys are treated as empty sketches.
  • PFMERGE destkey sourcekey [sourcekey ...] -- merges all source sketches into destkey (which may or may not already exist). For each register position, takes the maximum value across all sources and the existing dest. Returns :ok.

Summary

Functions

Handles a HyperLogLog command.

Functions

handle(cmd, args, store)

@spec handle(binary(), [binary()], map()) :: term()

Handles a HyperLogLog command.

Parameters

  • cmd - Uppercased command name ("PFADD", "PFCOUNT", or "PFMERGE")
  • args - List of string arguments
  • store - Injected store map with get, put, exists? callbacks

Returns

Plain Elixir term: integer, :ok, or {:error, message}.