Distributed primitives for Rust, backed by Redis.
distkit gives you the building blocks distributed services keep reinventing - counters, instance-aware counters, locks, and rate limiting - behind small, async APIs that mirror the std and tokio types you already know. #![forbid(unsafe_code)], no panics in library code.
[dependencies] distkit = "0.5"
use distkit::{DistkitRedisKey, counter::{StrictCounter, CounterOptions, CounterTrait}}; let conn = redis::Client::open("redis://127.0.0.1/")? .get_connection_manager().await?; let prefix = DistkitRedisKey::try_from("my_app".to_string())?; let counter = StrictCounter::new(CounterOptions::new(prefix, conn)); let key = DistkitRedisKey::try_from("page_views".to_string())?; counter.inc(&key, 1).await?;
One toolkit, four primitives
Each primitive is its own opt-in feature. Pull in only what you use - the core counters ship by default.
Built to be predictable
Safe by default
#![forbid(unsafe_code)] and no panics in library code. Errors surface through one DistkitError enum.
Strict or lax, your call
Choose immediate consistency when accuracy is critical, or buffered writes when throughput matters. Same trait, different guarantees.
Atomic where it counts
Strict operations execute Lua scripts so a single Redis round-trip is atomic - no read-modify-write races across instances.
Self-cleaning background tasks
Flush and lease-renewal tasks hold Weak references and stop on their own when the owning value is dropped.

