$ show RedisLabsModules/redismodule-rs
This repository is a Rust SDK/framework for building Redis modules, not an end-user application or data/research project. The workspace is organized as a library crate (`redis-module`) plus proc-macro helper crates (`redismodule-rs-macros`, `redismodule-rs-macros-internals`) that wrap the Redis Modules C API. Build code consumes vendored `redismodule.h` through `bindgen`, and the public API provides safe `Context`, `RedisKey`, `RedisString`, `RedisValue`, `RedisModuleIO`, configuration, key cursors, timers, blocking clients, thread-safe contexts, and command/info-handler registration. `redis_module!` and `#[command]` are the main module entry points; the included examples are small runnable modules, and integration tests spawn real `redis-server` processes to exercise them. Architecturally, the crate uses an unsafe FFI layer (`src/raw.rs`) underneath higher-level modules (`src/context/`, `src/key.rs`, `src/configuration.rs`, `src/io.rs`), and uses `linkme::distributed_slice` plus procedural macros to collect command, event, info, and defrag handlers. API-version compatibility is handled by feature flags (`min-redis-compatibility-version-6-0` through `8-0`) with a manual mapping table in `redismodule-rs-macros-internals/src/api_versions.rs`. The vendored C header includes Redis Labs / BigRedis extensions, reflecting production use inside Redis Enterprise modules. External build dependencies include `bindgen`, `cc`, libclang, and a Redis-compatible server for tests. The codebase is well structured for a low-level FFI SDK and contains several genuinely reusable patterns, but it has meaningful caveats: generated bindings are not committed, `bindgen` is pinned to an old version, the manual API-version table must be kept in sync as Redis evolves, and the FFI layer is necessarily large and unsafe. Overall it is an actively maintained, professional-quality SDK with a few deprecated APIs and some fragility around version-gated calls.
The LLM identified 5 files worth highlighting for reuse:
Implements a GlobalAlloc that routes all Rust allocations through RedisModule_Alloc/Realloc/Free, with a panic-safe fallback. This is a self-contained pattern for Rust libraries loaded into a host process where ownership of memory must be transferred to and from the host runtime.
Contains the API_VERSION_MAPPING table used by the `api!` macro to emit RedisModule_* wrappers only for the minimum Redis compatibility version selected by the build. Demonstrates a reusable pattern for versioning FFI bindings against a changing C API without breaking compilation.
Provides ThreadSafeContext and RedisGILGuard, wrapping Redis's global interpreter lock so background threads can safely call back into Redis, plus the RedisLockIndicator trait for statically indicating GIL ownership. The pattern is directly transferable to any Rust crate that must synchronize with a non-Send host runtime.
Implements an InfoContext builder that incrementally constructs Redis INFO output with duplicate-key detection and structured sections. This is a clean, self-contained example of building host-format report strings without leaking FFI types.
The `#[command]` attribute parses a JSONY command specification into typed CommandInfo, including arity, flags, key specs, and command metadata, then registers it with Redis on module load. This shows how to turn a domain-specific declarative format into runtime registration through procedural macros.