RKVS - Rust Key-Value Storage
A high-performance, namespace-based key-value storage system built in Rust. RKVS provides persistent storage with configurable limits, async operations, and atomic batch processing.
Features
- ð High Performance: Optimized for speed with async operations and efficient data structures
- ð Namespace Support: Organize data into isolated namespaces with individual configurations
- ⥠Atomic Operations: Batch operations with all-or-nothing semantics
- ðū Persistence: Optional file-based persistence with automatic serialization
- ð Thread-Safe: Built on Tokio's async primitives for concurrent access
- ð Rich Metadata: Track key counts, sizes, and namespace statistics
- ðŊ Configurable Limits: Set per-namespace limits for keys and value sizes
- ð Atomic Consume: Get and delete operations in a single atomic step
Quick Start
Add RKVS to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Basic Usage
use ;
async
Batch Operations
RKVS supports efficient batch operations for processing multiple key-value pairs:
use ;
async
Configuration
Configure storage and namespace limits:
use ;
// Global storage configuration
let storage_config = StorageConfig ;
// Per-namespace configuration
let namespace_config = NamespaceConfig ;
let storage = builder
.with_config
.with_persistence
.build;
Performance
RKVS is designed for high performance with the following characteristics:
- Namespace Operations: ~370ns (create), ~427ns (get), ~457ns (delete)
- Key-Value Operations: ~790ns (small values), ~1.84Ξs (large values)
- Batch Operations: Linear scaling with 3-8% improvement over individual operations
- Concurrent Access: Optimized for read-heavy workloads with RwLock-based synchronization
See the benchmark results for detailed performance metrics.
API Reference
Core Types
StorageManager: Main entry point for managing namespacesNamespace: Handle for working with a specific namespaceNamespaceConfig: Configuration for namespace limitsStorageConfig: Global storage configurationBatchResult<T>: Result of batch operations with metadata
Key Methods
StorageManager
create_namespace(name, config)- Create a new namespacenamespace(hash)- Get a namespace handledelete_namespace(hash)- Remove a namespacelist_namespaces()- List all namespacessave()/load()- Persistence operations
Namespace
set(key, value)- Store a key-value pairget(key)- Retrieve a valuedelete(key)- Remove a keyexists(key)- Check if key existsconsume(key)- Atomically get and deleteset_multiple(items)- Batch set operationget_multiple(keys)- Batch get operationdelete_multiple(keys)- Batch delete operationconsume_multiple(keys)- Batch consume operation
Error Handling
RKVS uses a unified error type RkvsError with the following variants:
Storage: File I/O and storage-related errorsSerialization: Data serialization/deserialization errorsInternal: Internal system errors
use ;
async
Thread Safety
RKVS is fully thread-safe and designed for concurrent access:
- All operations are async and can be safely called from multiple tasks
- Read operations can run concurrently within a namespace
- Write operations are serialized per namespace
- Batch operations provide atomicity guarantees
Persistence
RKVS supports optional file-based persistence:
let storage = builder
.with_persistence
.build;
// Save all data to disk
storage.save.await?;
// Load data from disk
storage.load.await?;
Data is automatically serialized using bincode for efficient storage.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Changelog
v0.1.0
- Initial release
- Namespace-based storage
- Async operations
- Batch processing
- File persistence
- Comprehensive benchmarking