basteh 0.4.0-alpha.2

Generic kv storage with replaceable backend
Documentation
basteh-0.4.0-alpha.2 has been yanked.

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.

Install

Basteh is meant to be used alongside one the implementer crates, ex:

# Cargo.toml
[dependencies]
basteh = "0.4.0-alpha.2"
basteh-memory = "0.4.0-alpha.2"

Usage

After you picked a backend:

use basteh::{Storage, Format};
use basteh_memory::MemoryBackend;

async fn make_storage() -> Storage {
   // Intialize the implementer according to its docs
   let store = MemoryBackend::start_default();

   // Give it to the Storage struct
   let storage = Storage::build().store(store).finish();

   // Or if it doesn't support expiring functionality
   // it will give errors if those methods are called
   let storage = Storage::build().store(store).no_expiry().finish();

   // It is also possible to feed a seprate expiry,
   // as long as it works on the same storage backend
   let storage = Storage::build().store(store).expiry(expiry).finish();
   
   storage
}

Implementations

basteh-memory

basteh-sled

basteh-redis

Use cases

It can be usefull when:

  1. You don't know which key-value database you'll need later.
  2. You can't afford the long time compilation of some dbs while developing.
    • memory store compiles pretty fast
  3. You're writing an extension library and need to support multiple storage backends.

Examples

There are bunch of examples in the examples folder, very basic ones thought, but it will give you the idea.

License

This project is licensed under either of

at your option.