Crates.io | hurrahdb |
lib.rs | hurrahdb |
version | 0.1.0 |
source | src |
created_at | 2023-03-12 20:23:27.541034 |
updated_at | 2023-03-12 20:23:27.541034 |
description | Hurrahdb is an persistent(AOF) inmemory key value store in Rust. |
homepage | https://github.com/olimpias/hurrahdb |
repository | https://github.com/olimpias/hurrahdb |
max_upload_size | |
id | 808261 |
size | 30,228 |
Hurrahdb is an inmemory key value store with an option of persistance in Rust. Currently only supports AOF option to persist.
Persistance of the data using AOF is async and flushing data into db based on sync_time
. Unit of the sync_time
in milliseconds.
While caching/storing a data, key needs to be string
type and value needs to be a struct or enum that derives Serialize
and Deserialize
from serde
library. An example model below
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct DummyStruct {
value: String,
}
When a storage is constracted without any config, it will not initilize any persistance logic.
// define a storage object with None
let storage = match Storage::new(None) {
Ok(storage) => storage,
Err(err) => {
// Handle the error
}
};
// Cache the `DummyStruct` struct with key "some-key"
match storage.set(
"some-key".to_string(),
&DummyStruct {
value: "some-value".to_string(),
},
) {
Ok(()) => {}
Err(err) => {
// Handle the error
}
}
// Fetch the `DummyStruct` data using key "some-key"
let result_option: Option<DummyStruct> = match storage.get("some-key".to_string()) {
Ok(result) => result,
Err(err) => {
// Handle the error
}
};
When a storage is created with AOF config, it reads the input file and precreates the hashmap with the data in the file. In addition to that creates a background job to flush data into disk based on sync_time
value.
Note:
tokio run time
Example usage here
// Define a storage with AOF config. Flushes data into file every 100ms.
let storage = match Storage::new(Some(Config {
aof_config: Some(AofConfig {
sync_time: 100,
file_name: "memory-cache-test-1".to_string(),
}),
persistance_type: persistance::Type::AOF,
})) {
Ok(storage) => storage,
Err(err) => {
// Handle the error
}
};
// Cache the `DummyStruct` struct with key "some-key"
match storage.set(
"some-key".to_string(),
&DummyStruct {
value: "some-value".to_string(),
},
) {
Ok(()) => {}
Err(err) => {
// Handle the error
}
}
// Fetch the `DummyStruct` data using key "some-key"
let result_option: Option<DummyStruct> = match storage.get("some-key".to_string()) {
Ok(result) => result,
Err(err) => {
// Handle the error
}
};