Crates.io | kvdb-lib |
lib.rs | kvdb-lib |
version | 0.1.6 |
source | src |
created_at | 2024-07-10 13:33:30.989498 |
updated_at | 2024-07-11 12:29:54.254777 |
description | A simple thread-safe key-value storage library using DashMap. |
homepage | https://github.com/messengernew/kvdb-lib |
repository | https://github.com/messengernew/kvdb-lib |
max_upload_size | |
id | 1298251 |
size | 7,036 |
A simple thread-safe key-value storage library using DashMap.
Add kvdb-lib
to your Cargo.toml
:
[dependencies]
kvdb-lib = "0.1.6"
Add the following to your main file:
use kvdb_lib::Storage;
fn main() {
let storage = Storage::new();
storage.set(1, "value1");
println!("{:?}", storage.get(&1));
}
Create a new Storage
instance:
use kvdb_lib::Storage;
let storage: Storage<i32, &str> = Storage::new();
Insert a key-value pair:
use kvdb_lib::Storage;
let storage = Storage::new();
storage.set(1, "value1");
Retrieve a value by its key:
use kvdb_lib::Storage;
let storage = Storage::new();
storage.set(1, "value1");
assert_eq!(storage.get(&1), Some("value1"));
Remove a key-value pair:
use kvdb_lib::Storage;
let storage = Storage::new();
storage.set(1, "value1");
storage.remove(1);
assert_eq!(storage.get(&1), None);
Retrieve all key-value pairs:
use kvdb_lib::Storage;
let storage = Storage::new();
storage.set(1, "value1");
storage.set(2, "value2");
let all = storage.get_all();
assert!(all.contains(&(1, "value1")));
assert!(all.contains(&(2, "value2")));
This project is licensed under the MIT License.