Crates.io | storage-trait |
lib.rs | storage-trait |
version | 0.1.4 |
source | src |
created_at | 2022-07-24 10:34:41.686881 |
updated_at | 2022-08-03 07:11:11.957733 |
description | A simple k-v pair storage trait |
homepage | |
repository | https://github.com/ZBcheng/storage-trait |
max_upload_size | |
id | 631918 |
size | 22,991 |
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"
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")
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