hurrahdb

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.

Usage

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

```rust use serde::{Deserialize, Serialize};

[derive(Serialize, Deserialize)]

struct DummyStruct { value: String, } ```

Only In-memory

When a storage is constracted without any config, it will not initilize any persistance logic.

```rust // 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".tostring(), &DummyStruct { value: "some-value".tostring(), }, ) { Ok(()) => {} Err(err) => { // Handle the error } }

// Fetch the DummyStruct data using key "some-key" let resultoption: Option = match storage.get("some-key".tostring()) { Ok(result) => result, Err(err) => { // Handle the error } }; ```

Inmemory With AOF

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:

Example usage here

```rust

// Define a storage with AOF config. Flushes data into file every 100ms. let storage = match Storage::new(Some(Config { aofconfig: Some(AofConfig { synctime: 100, filename: "memory-cache-test-1".tostring(), }), 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".tostring(), &DummyStruct { value: "some-value".tostring(), }, ) { Ok(()) => {} Err(err) => { // Handle the error } }

// Fetch the DummyStruct data using key "some-key" let resultoption: Option = match storage.get("some-key".tostring()) { Ok(result) => result, Err(err) => { // Handle the error } }; ```