Hiredis Client Integration
This page documents the hiredis compatibility feature and integration patterns for:
redis-py(throughhiredis-py)- Other libraries that link to
libhiredis
Feature model
Section titled “Feature model”redis-web-hiredis-compat exports a hiredis-compatible C ABI (libhiredis) so existing consumers can relink without source-level changes.
Current implementation status:
- Full upstream hiredis symbol parity for the pinned upstream version in this repository harness
- Full upstream header API name parity for
hiredis.h,read.h,alloc.h, andsds.h - Runtime behavior parity provided by staged upstream hiredis core + async C runtime
- Parser/reader and transport/async behavior validated by redis-py standalone compatibility runs and runtime fixtures
Integration architecture
Section titled “Integration architecture”flowchart LR C["Client library"] --> H["hiredis headers + libhiredis ABI"] H --> RW["redis-web-hiredis-compat"] RW --> P["RESP parser and callback surface"]redis-py path
Section titled “redis-py path”redis-py uses hiredis-py when available. The hiredis-py extension links against libhiredis.
flowchart TD RP["redis-py"] --> HP["hiredis-py C extension"] HP -->|"dynamic link: -lhiredis"| HC["compat libhiredis"] HC --> RESP["reader callbacks + parsed replies"]The local harness in this repository automates this flow:
- Build compat artifacts from
crates/redis-web-hiredis-compat. - Patch and rebuild
hiredis-pyto link externally. - Install patched wheel into an isolated venv.
- Run redis-py standalone tests.
Artifact and script lifecycle
Section titled “Artifact and script lifecycle”The recommended lifecycle for both validation and one-off consumer runs is:
- Prepare submodule and redis-py build environment:
make compat_redispy_bootstrap- Stage compat headers/libs/pkconfig and build a redis-py+
hiredis-pywheel against them:
make compat_redispy_build_hiredis- Run symbol/header audit before broader runtime checks:
make compat_redispy_audit- Optionally include SSL parity verification:
make compat_ssl_audit- Run redis-py compatibility smoke/regression:
make compat_redispy_regressionmake compat_redispy_testArtifacts are staged through subprojects/redispy-hiredis-compat/.dist/hiredis/ and
.artifacts/ by the script chain, and symbol audits emit:
hiredis-missing-symbols.txthiredis-missing-vs-upstream-symbols.txthiredis-missing-header-api.txt
Commands
Section titled “Commands”make compat_redispy_bootstrapmake compat_redispy_build_hiredismake compat_redispy_auditmake compat_ssl_auditmake compat_redispy_regressionmake compat_redispy_testManual script flow:
subprojects/redispy-hiredis-compat/scripts/build-compat-artifacts.shsubprojects/redispy-hiredis-compat/scripts/build-hiredis-wheel.shsubprojects/redispy-hiredis-compat/scripts/setup-test-env.shsubprojects/redispy-hiredis-compat/scripts/run-redispy-tests.shsetup-test-env.sh defaults to build/install only (VERIFY_HIREDIS_ACTIVE=0), so it does not require a live Redis endpoint unless runtime verification is explicitly enabled.
Runtime verification
Section titled “Runtime verification”subprojects/redispy-hiredis-compat/scripts/verify-hiredis-active.py --db 0This checks that redis-py is actively using a hiredis parser.
Redis test topology used by harness
Section titled “Redis test topology used by harness”flowchart LR T["run-redispy-tests.sh"] --> M["redis:6379 master"] T --> R["redis:6380 replica"] M --> RNotes:
- Managed mode is on by default (
MANAGED_REDIS=1). - On ARM hosts, the harness defaults docker platform to
linux/amd64to match redis-py GEO precision fixtures.
Using with other hiredis-linked libraries
Section titled “Using with other hiredis-linked libraries”For any library that expects hiredis headers and -lhiredis:
- Build compat artifacts:
subprojects/redispy-hiredis-compat/scripts/build-compat-artifacts.sh- Export compiler/linker paths:
source subprojects/redispy-hiredis-compat/.dist/hiredis/env.sh-
Build your consumer normally (pkg-config or explicit include/lib flags).
-
Set runtime loader paths as needed:
# macOSexport DYLD_LIBRARY_PATH="subprojects/redispy-hiredis-compat/.dist/hiredis/lib:$DYLD_LIBRARY_PATH"
# Linuxexport LD_LIBRARY_PATH="subprojects/redispy-hiredis-compat/.dist/hiredis/lib:$LD_LIBRARY_PATH"- Validate with the consumer’s own tests.
Optional audit hardening:
make compat_redispy_auditruns:- hiredis-py extension required-symbol gate (hard fail on missing).
- upstream hiredis/hiredis_ssl export and header API parity reports.
make compat_ssl_auditadditionally validates staged SSL symbol/runtime linkage.- Set
STRICT_UPSTREAM_PARITY=1to hard-fail if any upstream parity gaps are detected.
Compatibility limits
Section titled “Compatibility limits”This integration now provides full symbol/header parity and runtime parity by using upstream hiredis runtime sources for staged artifacts.
- Supported: redis-py + hiredis-py compatibility path, strict upstream audit parity, and runtime command/transport behavior.
- SSL parity is provided via staged
libhiredis_sslusing upstream hiredis split-library semantics.
For implementation-level details and local harness usage, see:
subprojects/redispy-hiredis-compat/USAGE.md