idempotent
Idempotency library with at-most-once execution and response caching.
Highlights
- Typestate entries:
Processing→Completedis checked at compile time, so you can't forget to complete an entry or complete one twice - Pluggable stores: comes with an in-memory store and a Valkey/Redis store; implement
IdempotencyStorefor your own backend - Fencing tokens: rejects stale completions when a key expires and gets reclaimed while the original request is still running
- Fingerprint matching: returns a conflict when a retry carries a different request body than the original; ships with an xxHash-based default, implement
FingerprintStrategyfor your own - UUID keys by default:
IdempotencyKey::default()generates a random UUID v4
Usage
Add to your Cargo.toml
[]
= { = "0.3.0", = ["memory"] }
Quick example
use ;
use ;
use MemoryStore;
let store = new;
let key = default;
let fingerprint = DefaultFingerprintStrategy.compute;
let entry = new;
match store.try_insert.await?
Optional features
- memory: enables the in-memory store, suitable for development or single-node deployment
- valkey: enables the Valkey/Redis store, using Lua scripts for atomic operations
- tracing: instruments store operations with
tracingspans and events - serde: derives
SerializeandDeserializeonIdempotencyKey,IdempotencyEntry,Fingerprint, andFencingToken
Supported Rust versions
The minimum supported Rust version is 1.94.0.
License
Unless otherwise noted, this project is licensed under the Mozilla Public License Version 2.0.