Ferricstore.Commands.TDigest (ferricstore v0.3.3)

Copy Markdown View Source

Handles Redis-compatible TDIGEST.* commands.

A t-digest is a probabilistic data structure for accurate on-line accumulation of rank-based statistics such as quantiles, trimmed means, and cumulative distribution values. It provides high accuracy at the tails (P99, P99.9) while using bounded memory.

Storage format

T-digests are stored as tagged tuples via the injected store map:

{:tdigest, centroids_list, metadata}

where centroids_list is a list of {mean, weight} tuples sorted by mean, and metadata is a map containing compression, count, min, max, buffer, and total_compressions.

Supported commands

  • TDIGEST.CREATE key [COMPRESSION compression] -- create a new t-digest
  • TDIGEST.ADD key value [value ...] -- add observations
  • TDIGEST.RESET key -- clear data, preserve compression
  • TDIGEST.QUANTILE key quantile [quantile ...] -- estimate values at quantiles
  • TDIGEST.CDF key value [value ...] -- estimate CDF at values
  • TDIGEST.RANK key value [value ...] -- estimate rank of values
  • TDIGEST.REVRANK key value [value ...] -- estimate reverse rank
  • TDIGEST.BYRANK key rank [rank ...] -- estimate value at rank
  • TDIGEST.BYREVRANK key rank [rank ...] -- estimate value at reverse rank
  • TDIGEST.TRIMMED_MEAN key low_quantile high_quantile -- trimmed mean
  • TDIGEST.MIN key -- minimum observed value
  • TDIGEST.MAX key -- maximum observed value
  • TDIGEST.INFO key -- digest metadata
  • TDIGEST.MERGE destkey numkeys src [src ...] [COMPRESSION c] [OVERRIDE]

Summary

Functions

Handles a TDIGEST command.

Functions

handle(cmd, args, store)

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

Handles a TDIGEST command.

Parameters

  • cmd -- uppercased command name (e.g. "TDIGEST.CREATE")
  • args -- list of string arguments
  • store -- injected store map with get, put, exists? callbacks

Returns

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