#key-value #key-value-store #thread-safe #dash-map #kv-db #lib #pair

kvdb-lib

A simple thread-safe key-value storage library using DashMap

3 releases

0.1.6 Jul 11, 2024
0.1.5 Jul 11, 2024

#1972 in Database interfaces

Download history 413/week @ 2024-07-07 27/week @ 2024-07-14

131 downloads per month

MIT license

6KB

Key: Value database library

A simple thread-safe key-value storage library using DashMap.

Usage

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));
}

Examples

Creating a Storage

Create a new Storage instance:

use kvdb_lib::Storage;

let storage: Storage<i32, &str> = Storage::new();

Setting a Key-Value Pair

Insert a key-value pair:

use kvdb_lib::Storage;

let storage = Storage::new();
storage.set(1, "value1");

Getting a Value

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"));

Removing a Key-Value Pair

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);

Getting All Key-Value Pairs

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")));

License

This project is licensed under the MIT License.

Dependencies

~1–6MB
~22K SLoC