9 releases (1 stable)
1.0.0 | Oct 13, 2023 |
---|---|
0.2.5 | Oct 7, 2023 |
0.1.3 | Oct 5, 2023 |
#2903 in Database interfaces
83 downloads per month
75KB
1.5K
SLoC
Quick-KV
A reliable key-value storage for modern software
Features
- Binary Based Data-Store
- Serde Supported Data Types
- Thread Safe
Links
Documentation | Crates.io | Github
Installation
cargo add quick-kv
Examples
use quick_kv::prelude::*;
fn main() -> anyhow::Result<()>
{
let mut client = QuickClient::<String>::new(None);
client.get("star this repo")?;
Ok(())
}
CLI (Beta)
Quick-KV comes with a REPL for interacting with the database.
To install the CLI, run the following command:
cargo install quick-kv
This is different from the cargo add
command because it installs the CLI globally allowing you to use it as a executable.
lib.rs
:
QuickKV is a simple, fast, and easy to use key-value store.
Features
- Simple API
- Built-in Logging
- I/O Caching
- CLI tool (Beta)
Useful Links
Documentation | Crates.io | Github
Examples
use std::io;
use quick_kv::prelude::*;
use rand::Rng;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
struct GuessingGame
{
tries: u32,
incorrect_guesses: Vec<u32>,
}
fn main() -> anyhow::Result<()>
{
let mut client = QuickClient::<GuessingGame>::new(ClientConfig::default());
// First, we create a new game.
let game = GuessingGame {
tries: 0,
incorrect_guesses: vec![],
};
// Set the game in the client.
client.set("game", game.clone())?;
println!("Welcome to the Number Guessing Game!");
println!("You have 5 attempts to guess a number between 1 and 50.");
let secret_number = rand::thread_rng().gen_range(1..50);
loop {
let game_state = client.get("game")?.unwrap();
let remaining_attempts = 5 - game_state.tries;
if remaining_attempts == 0 {
println!("Sorry, you have lost the game!");
println!("The secret number was {}.", secret_number);
client.delete("game")?;
break;
}
println!("Attempts left: {}", remaining_attempts);
println!("Please input your guess:");
let mut guess = String::new();
io::stdin().read_line(&mut guess).expect("Failed to read line");
if guess.trim().to_lowercase() == "quit" {
println!("Thanks for playing!");
break;
}
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("Please enter a valid number!");
continue;
}
};
if guess < 1 || guess > 50 {
println!("The secret number is between 1 and 50.");
continue;
}
if guess == secret_number {
println!("Congratulations! You guessed the correct number!");
client.delete("game")?;
break;
} else if guess < secret_number {
println!("Sorry, your guess was too low. Try a higher number!");
} else {
println!("Sorry, your guess was too high. Try a lower number!");
}
let updated_game = GuessingGame {
tries: game_state.tries + 1,
incorrect_guesses: game_state.incorrect_guesses.clone(),
};
client.update("game", updated_game, None)?;
}
Ok(())
}
More examples can be found in the examples directory.
Dependencies
~4–15MB
~145K SLoC