Crates.io | basteh |
lib.rs | basteh |
version | 0.4.0-alpha.5 |
source | src |
created_at | 2023-02-01 08:49:18.202105 |
updated_at | 2023-03-06 18:22:56.142803 |
description | Generic kv storage with replaceable backend |
homepage | |
repository | https://github.com/pooyamb/basteh/ |
max_upload_size | |
id | 773422 |
size | 61,144 |
Note The main branch includes many breaking changes, switch to v0.3 branch for the released version.
Basteh(previously actix-storage) is a type erased wrapper around some key-value storages to provide common operations.
Basteh is meant to be used alongside one the implementer crates, ex:
# Cargo.toml
[dependencies]
basteh = "0.4.0-alpha.5"
basteh-memory = "0.4.0-alpha.5"
After you picked a backend:
use basteh::{Basteh, BastehError};
use basteh_memory::MemoryBackend;
async fn handler() -> Result<String, BastehError> {
// Intialize the implementer according to its docs
let store = MemoryBackend::start_default();
// Give it to the Storage struct
let basteh = Basteh::build().store(store).finish();
// Set a key, value can be stringy, bytes or numbers
basteh.set("key", "value").await;
// And make it expire after 5 seconds
basteh.expire("key", Duration::from_secs(5)).await;
// Or just do both in one command(usually faster)
basteh.set_expiring("key", "value", Duration::from_secs(5)).await;
basteh.get::<String>("key").await
}
There is also an implementation based on sled, but because of sled's situation, it has not been released to crates.io
The word basteh
is persian for box/package, that simple! Does it sound like some other words in english? sure! But I'm bad at naming packages and my other option was testorage
as in type-erased storage... so... basteh
is cool.
The main idea for having a kv storage around while developing applications, came from my love for django framework and how it makes your life easier. There is a cache framework in django that does just that! Basteh is a bit more, it is not just for a cache but also for persistent values which is why there will always be some persistent implementations around.
Although it is designed to work with small, mostly temporary data, I don't have any plans to make it less effecient for other workflows, and pull requests are always welcome.
It can be usefull when:
There are bunch of examples in the examples
folder, very basic ones thought, but it will give you the idea.
This project is licensed under either of
at your option.