storage-trait

Crates.iostorage-trait
lib.rsstorage-trait
version0.1.4
sourcesrc
created_at2022-07-24 10:34:41.686881
updated_at2022-08-03 07:11:11.957733
descriptionA simple k-v pair storage trait
homepage
repositoryhttps://github.com/ZBcheng/storage-trait
max_upload_size
id631918
size22,991
bee0_0 (ZBcheng)

documentation

README

storage-trait

A simple k-v pair storage trait, including the implementation of dashmap and redis.

Depending on this crate via cargo:

[dependencies]
storage-trait = "0.1.4"

Dashmap Support

You can build a dashmap storage object implmenting storage trait by using methods below:

use storage_trait::{DashMapStorageBuilder, Storage};

fn set_get() {
    let storage = DashMapStorageBuilder::new().build();
    let _ = storage
        .set("name".to_string(), "Ferris".to_string())
        .unwrap();
    let resp = storage.get("name".to_string()).unwrap();
    println!("resp: {:?}", resp);
}

output:

resp: Some("Ferris")

Redis Support(single node)

Build a redis storage object:

use storage_trait::{RedisStorageBuilder, Storage};

fn set_contains() {
    let storage = RedisStorageBuilder::new()
        .addr("redis://127.0.0.1:6379")
        .build();
    let _ = storage
        .set("name".to_string(), "Ferris".to_string())
        .unwrap();
    let resp = storage.contains("name".to_string()).unwrap();
    println!("resp: {:?}", resp);
}

output:

resp: true
Commit count: 24

cargo fmt