valkey-datasketches is a Valkey module that provides probabilistic data structure commands (CPC, HLL, Theta, KLL, etc.) powered by the DataSketches family of algorithms.
- Fully implemented sketch families:
CPC,HLL,Theta,KLL,REQ,Reservoir,LongSketch,ItemSketch - Placeholder command modules only:
TDigest,Tuple,VarOpt SKETCH.INFOreports the implemented algorithms from the registry insrc/sketches/algorithms.cc
- CMake 3.17+ with C++11 standard (strict — no C++14/17 features)
- Build generator: Ninja (via
build.sh) or Make - Main library target:
libdatasketches(shared .so/.dylib) - Build:
./build.sh --release(fast, module only) orcmake -B build -G Ninja && ninja - Unit tests:
./build.sh --unitor./build/tst/unit/unitTests - Integration tests:
./build.sh --integrationortst/integration/run.sh test - Lint:
scripts/lint.sh
| Variable | Default | Description |
|---|---|---|
VALKEY_SOURCE_DIR |
(none) | Path to a local Valkey source tree. When set, skips GitHub clone and copies valkeymodule.h directly. Required for fast builds. |
VALKEY_DS_DEPS_CACHE |
build/_deps |
Shared cache for Valkey/GoogleTest builds across worktrees. |
SERVER_VERSION |
unstable |
Valkey version tag (e.g. 8.1). |
ASAN_BUILD |
(none) | Set to enable Address Sanitizer. |
CFLAGS |
-g -O3 -fno-omit-frame-pointer -Wall -Werror -Wextra |
Override compiler flags. |
| Option | Default | Description |
|---|---|---|
BUILD_RELEASE |
OFF |
Build only the module, skip tests and Valkey compilation. |
ENABLE_UNIT_TESTS |
ON |
Build GoogleTest unit tests. |
ENABLE_INTEGRATION_TESTS |
ON |
Build integration tests (requires Valkey compilation). |
ENABLE_ASAN |
OFF |
Enable Address Sanitizer. |
VALKEY_SOURCE_DIR |
(none) | Path to local Valkey source (see env var above). |
DEPS_CACHE_DIR |
build/_deps |
Override dependency cache location. |
src/
├── module.cc # Module entry point (ValkeyModule_OnLoad)
├── include/ # Build-generated headers (valkeymodule.h) — DO NOT EDIT
├── commands/ # Command JSON metadata
├── modules/ # Per-algorithm Valkey module bindings (commands + type registration)
│ ├── cpc/ # CPC sketch commands + type registration
│ ├── hll/ # HLL sketch commands + type registration
│ ├── theta/ # Theta sketch commands + set operations
│ ├── tuple/ # Tuple sketch commands
│ ├── kll/ # KLL sketch commands + union support
│ ├── req/ # REQ sketch commands + union support
│ ├── tdigest/ # TDigest sketch commands
│ ├── longsketch/ # LongSketch frequent-items commands
│ ├── itemsketch/ # ItemSketch frequent-items commands
│ ├── countmin/ # CountMin sketch commands
│ ├── reservoir/ # Reservoir sampling commands + type registration
│ └── varopt/ # VarOpt sampling commands
└── sketches/ # Core sketch algorithm implementations / adapters
├── algorithms.h/cc # Algorithm registry
├── cpc_sketch.h/cc # CPC sketch algorithm
├── cpc_union.h/cc # CPC union algorithm
└── murmurhash3.h # Third-party hash (DO NOT LINT)
tst/
├── unit/ # GoogleTest unit tests
└── integration/ # Pytest integration tests (valkey-test-framework)
- C++ Standard: C++11 only. No
autoreturn types, nostd::make_unique, no structured bindings. - Include Order: Own header first, then system headers (alphabetical), then project headers (alphabetical).
- Access Specifiers: Indent with 1 space inside class body (
public:,private:). - Naming:
PascalCasefor classes/types,snake_casefor functions/variables,UPPER_CASEfor constants. - Command Registration: Each algorithm has
XxxCommands_Register(ValkeyModuleCtx *ctx)insrc/modules/{algo}/{algo}.cc. - Command Prefix: All commands use
SKETCH.{ALGO}.{VERB}naming (e.g.,SKETCH.CPC.ADD). - No comments unless explaining a non-obvious "why". No TODO/FIXME without a tracking issue.
- Explicit includes: Include the header for every symbol you use directly (e.g.
<cstddef>forsize_t,<cstdio>forsnprintf). Do not rely on transitive includes — macOS/libc++ pulls them in implicitly, but Linux CI (GCC/libstdc++) does not, causing CI-only build failures.
cpplint is configured via CPPLINT.cfg at project root. Disabled checks:
legal/copyright— no copyright headersbuild/header_guard— project uses own namingbuild/include_subdir— CMake-Ihandles pathswhitespace/line_length— limit is 120 (not 80)readability/casting— third-party code uses C-style castsruntime/int— ValkeyModule API requireslong long
Run locally: scripts/lint.sh
- Unit tests: GoogleTest, located in
tst/unit/. Run via./build/tst/unit/unitTests. - Unit coverage today:
cpc,hll,theta,kll,req,reservoir,longsketch,itemsketch, plus module-level registry tests. - Integration tests: Pytest with
valkey-test-framework. Each algorithm hastst/integration/test_{algo}.py.- Base class:
DataSketchesTestCase(intst/integration/datasketches_test_case.py) - Replication tests inherit
ReplicationTestCasefromvalkeytests.valkey_test_case - Shared setup uses the
setup_testautouse fixture defined onDataSketchesTestCase tdigest,tuple, andvaroptintegration tests currently validate placeholder command behavior
- Base class:
- Environment variables:
MODULE_PATH,SERVER_VERSION,PYTHONPATH,VALKEY_SOURCE_DIR
src/include/valkeymodule.his generated during configure/build from the Valkey source tree; do not modify it manually.- Third-party
src/sketches/murmurhash3.hshould not be linted or modified. - Module name is
valkey-datasketches, library output islibdatasketches. - For self-contained objects (no background tasks/external refs), only
freecallback is needed — skipunlink/unlink2.