Skip to content

store

KvStore trait + memory / file / sql / redis / redb backends for Sova

Cratesova-store 0.1.6
Plugin idstore
CategoryStorage

Install

bash
cargo add sova --features store

Features

FeatureWhat you get
storeKvStore + Cache (sessions, CSRF, rate-limit, …).
store-cryptoXChaCha20-Poly1305 wrapper for KvStore.
store-fileFile-backed KvStore.
store-redbEmbedded redb KvStore (file, no daemon).
store-redisRedis KvStore on RedisPool.
store-sqlSQL KvStore on DbPool.

Overview

When: byte KV for sessions, CSRF, rate-limit, cache.

Does:

  • KvStore + AppStore / SharedStore
  • memory / file / sql / redis / redb backends
  • namespace(store, "sess") / AppStore::namespaced for isolation
  • Optional crypto (store-crypto)

Example

rust
app.install(SharedStore::redb("./data/kv.redb")); // or ::memory() / ::sql(&app) / ::redis(&app)

Quick start

Shared KvStore for rate-limit, cache, session, etc. Soft-wire from Db/Redis or open embedded redb:

rust
use sova::prelude::*;
use sova::{Parser, ServerArgs, SharedStore};

#[tokio::main]
async fn main() -> Result<()> {
    let args = ServerArgs::parse();
    args.init_tracing();

    let mut app = App::web()
        .site("App")
        .public_url("https://example.com")
        .into_app();

    // Embedded (no daemon):
    app.install(SharedStore::redb("./data/kv.redb"));
    // Or: SharedStore::memory() / ::sql(&app) after Db / ::redis(&app) after Redis

    app.run().await
}

Namespaces: app.try_state::<AppStore>().unwrap().namespaced("sess").

Features: store-sql, store-redis, store-redb, store-file, store-crypto.

Examples

session · redis · rate-limit · csrf · idempotency · response-cache