Crate cuttlestore

source ·
Expand description

Cuttlestore is a generic API for key-value stores that can be backed by different storage backends. Cuttlestore allows you to build applications that can be deployed to use different storage options: a small deployment can use an Sqlite backend to simplify operations while a large deployment can use Redis for better scalability.

use cuttlestore::{Cuttlestore, PutOptions};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct SelfDestructingMessage {
    message: String,
}

let store: Cuttlestore<SelfDestructingMessage> = Cuttlestore::new("redis://127.0.0.1")
    .await
    .unwrap();

let mission = SelfDestructingMessage {
  message: "Your mission, should you choose to accept it, ...".to_string(),
};
store
  .put_with("impossible", &mission, PutOptions::ttl_secs(60))
  .await
  .unwrap();

// Later

let value: Option<SelfDestructingMessage> = store.get("impossible").await.unwrap();
println!("Message says: {value:?}");

Structs

A connection to the backing data store. You can use this connection to create one or more Cuttlestore instances, which will share their connections.
A basic key-value store. This is the primary API you’ll interact with.
Configure a Cuttlestore.
Options to use when placing a value into a store.