Crates.io | skv |
lib.rs | skv |
version | 0.1.2 |
source | src |
created_at | 2023-06-18 22:57:18.256654 |
updated_at | 2023-07-16 18:21:18.909919 |
description | A simple thread-safe disk-backed key-value store |
homepage | |
repository | |
max_upload_size | |
id | 893665 |
size | 46,898 |
A simple key-value store written in Rust.
skv
implements a basic thread-safe key-value store that persists data to disk. It maintains an index to quickly lookup data offsets in the storage file. Key-value pairs can be inserted into the store with the insert
method and retrieved with the get
method. The store's state can be loaded from disk using the load
method, and a new store can be created with the new
method.
use skv::KeyValueStore;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new key-value store
let kv_store = KeyValueStore::new("kv_store.db", "kv_index.db")?;
// Insert some key-value pairs
kv_store.insert("key1".to_string(), "value1".to_string())?;
kv_store.insert("key2".to_string(), "value2".to_string())?;
// Retrieve some key-value pairs
println!("{:?}", kv_store.get("key1"));
println!("{:?}", kv_store.get("key2"));
Ok(())
}
use skv::KeyValueStore;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new key-value store with a type that can be serialized
// as a byte array. In this case, we use a fixed size array.
let kv_store = KeyValueStore::<[u8;2]>::new("kv_store.db", "kv_index.db")?;
// Insert some key-value pairs
kv_store.insert("key1".to_string(), [0, 1])?;
kv_store.insert("key2".to_string(), [2, 3])?;
// Retrieve some key-value pairs
println!("{:?}", kv_store.get("key1"));
println!("{:?}", kv_store.get("key2"));
Ok(())
}
TLDR; skv
is pretty fast. Read take ~18µs and writes take ~750µs 🏎️
Please run cargo bench
to run the benchmarks on your machine to get a better idea of how skv
performs. The following benchmarks were run on a 2019 MBP, they may not be representative of your machine.
Benchmark | Lower | Estimate | Upper |
---|---|---|---|
random reads | 17.544 µs | 17.774 µs | 18.035 µs |
random writes | 710.12 µs | 756.05 µs | 804.26 µs |
sequential reads | 17.864 µs | 18.160 µs | 18.497 µs |
sequential writes | 698.29 µs | 746.16 µs | 800.71 µs |
Below are some of the limitations of skv
. These limitations may be addressed in future versions, or may require a more complex implementation. skv
is intended stay exremely simple and easy to use and may not fit your use case.
String
key-value pairs