rmqtt-storage
Is a simple wrapper around some key-value storages.
Usage
Add this to your Cargo.toml:
[]
= "0.10"
Features
- Supports basic operations of key-value libraries.
- Supports Map data type and related operations.
- Supports List data type and related operations.
- Supports key expiration.
- Provides an implementation for 'sled'.
- Provides an implementation for 'redis'.
- Provides an implementation for 'redis cluster'. Note: the 'len' feature is not supported yet.
- Uses
postcardfor binary serialization. - Asynchronous API with command-based architecture for thread-safe operations.
- Circuit Breaker (optional): Protects Redis/Redis Cluster backends from cascading failures using
tower-resilience-circuitbreaker. Configure failure thresholds, sliding windows, and automatic recovery.
Feature Flags
| Feature | Description | Default |
|---|---|---|
sled |
Sled embedded database backend | no |
redis |
Single-node Redis backend | no |
redis-cluster |
Redis Cluster distributed backend | no |
ttl |
Key expiration / TTL support | no |
len |
Storage item count (len()) |
no |
map_len |
Map item count (map.len()) |
no |
circuit-breaker |
Circuit breaker protection (requires a storage backend) | no |
Circuit Breaker Usage
Enable the feature and wrap your storage with CircuitBrokenDB:
[]
= { = "0.10", = ["sled", "circuit-breaker"] }
use ;
use init_db;
let inner = init_db.await?;
let db = new;
// All existing APIs work transparently through the circuit breaker
let val: = db.get.await?;
let map = db.map.await?;
map.insert.await?;
CircuitBrokenDB implements the [StorageDB] trait, and CircuitBrokenMap/CircuitBrokenList implement the [Map]/[List] traits respectively. This means they can be used polymorphically alongside native storage backends in generic contexts.
When the failure rate exceeds the configured threshold, the circuit opens and subsequent calls fail fast instead of waiting for timeouts. After a configurable recovery period, the circuit transitions to half-open to test if the backend has recovered.
Operation Timeout
Set operation_timeout to abort calls that take longer than the specified duration. Timed-out calls are automatically counted as failures, triggering the circuit breaker:
use Duration;
use CircuitBreakerConfig;
let config = CircuitBreakerConfig ;
Changelog
0.9.0
- Serialization: Migrated from
bincodetopostcard— faster, smaller encoded output - Refactor: Removed sled transaction dependency, replaced with direct tree operations for better single-threaded throughput
- Testing: Added
serial_testto prevent sled I/O contention in parallel test runs
0.10.0
- Circuit Breaker: New
circuit-breakerfeature — wrapsDefaultStorageDB/StorageMap/StorageListwith per-instance fault tolerance viatower-resilience-circuitbreaker0.10- Sliding window failure rate detection (default: 50% over 20 calls)
- Half-Open automatic recovery (default: 30 s wait)
- Slow call detection (default: 2 s threshold)
- Operation timeout (
operation_timeout): abort hung calls and count as failures - State transition logging
- Independent breakers per DB / Map / List instance
- Trait implementation:
CircuitBrokenDBnow implementsStorageDBtrait,CircuitBrokenMapimplementsMaptrait,CircuitBrokenListimplementsListtrait — enabling polymorphic dispatch alongside native storage backends - Iterator methods (
map_iter,list_iter,scan,iter,key_iter,prefix_iter) bypass the circuit breaker for safe pass-through - Zero impact when feature is disabled
0.10.1
- Internal
_rawmethods: Added_insert_raw,_batch_insert_raw,remove_and_fetch_rawto Redis and Redis Cluster backends — bypasspostcardser/de forcircuit-breakerinternal useinsert_raw/batch_insert_rawrefactored to delegate to their_rawcounterpartsremove_and_fetch_raw— new raw-bytes variant ofremove_and_fetch
- CB optimization:
CBMapRequest::RemoveAndFetchnow uses a singleremove_and_fetch_rawcall instead ofget_raw+remove(fewer round trips, atomic) - Bug fix: Redis
_batch_insertnow guards against empty input to avoidMSETwith zero arguments - Tests: Added 7 new test cases —
push_limit,map_remove/list_remove(DB level), empty list pop/get_index, empty mapremove_and_fetch, large value (100KB), emptybatch_insert/batch_remove - Cleanup: Removed hanging CB integration tests (redundant with lib.rs
test_init_dbcoverage); fixedinit_dbreturn type and feature-gated imports inlib.rs