kora-server, but routes commands through direct function calls instead of TCP.
How It Works
EachDatabase instance owns a ShardEngine with a configurable number of shard worker threads. Keys are hashed to a shard, and commands are sent over an mpsc channel to that shard’s worker. The calling thread blocks on a oneshot channel until the worker replies, giving synchronous semantics with lock-free, shared-nothing execution.
Embedded vs. Server Mode
| Aspect | kora-embedded | kora-server |
|---|---|---|
| Transport | Direct function calls | TCP / Unix socket (RESP2) |
| Latency | Sub-microsecond dispatch | Network round-trip |
| Deployment | Linked into your binary | Separate process |
| Protocol | Rust types (Command / CommandResponse) | Wire-compatible RESP2 |
Quick Start
Addkora-embedded to your Cargo.toml:
Opening a Database
shard_count to the number of available hardware threads. You can customize it:
String Operations
Basic Get/Set
Set with Expiration
Atomic Counters
Batch Operations
String Utilities
Hash Operations
List Operations
Set Operations
Document Database
Kora includes a JSON-native document database with secondary indexes and query capabilities.Creating Collections and Inserting Documents
Reading Documents
Creating Indexes and Querying
Document Updates
Vector Search
Key Management
Hybrid Mode
With theserver feature enabled, you can embed the database AND expose a TCP listener for external clients:
ShardEngine.
Thread Safety
AllDatabase methods are safe to call from multiple threads. Wrap the database in an Arc for shared access:
Performance Considerations
- Shard count: Set to the number of CPU cores for optimal throughput. Each shard runs on its own OS thread.
- Key distribution: Kora uses a consistent hash to distribute keys across shards. Hot keys on the same shard won’t benefit from parallelism.
- Blocking calls: All operations block the calling thread until the shard worker responds. For async code, spawn blocking tasks or use Tokio’s
spawn_blocking. - Memory: Each shard maintains independent storage. Total memory usage scales with shard count and key count.
API Reference
For the complete API documentation, run:kora-embedded/src/lib.rs.