5 releases

0.1.4 Aug 3, 2022
0.1.3 Aug 1, 2022
0.1.2 Jul 31, 2022
0.1.1 Jul 25, 2022
0.1.0 Jul 24, 2022

#2557 in Database interfaces

Download history 2/week @ 2024-02-26 6/week @ 2024-03-11 45/week @ 2024-03-25

51 downloads per month

MIT license

12KB
311 lines

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

Dependencies

~4–11MB
~131K SLoC