Crate veddb_client

Crate veddb_client 

Source
Expand description

ยงVedDB Rust Client

Crates.io Documentation License: MIT

Official Rust client library and CLI for VedDB - A fast, lightweight in-memory key-value database.

This crate provides both a Rust library for embedding in your applications and a CLI tool (veddb-cli) for interactive database operations.

ยง๐Ÿš€ Quick Start

Add this to your Cargo.toml:

[dependencies]
veddb-client = "0.0.11"
tokio = { version = "1", features = ["full"] }

ยงBasic Example

use veddb_client::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
    // Connect to VedDB server
    let client = Client::connect("127.0.0.1:50051").await?;
     
    // Ping the server
    client.ping().await?;
    println!("Server is alive!");
     
    // Set a key-value pair
    client.set("name", "Alice").await?;
     
    // Get a value
    let value = client.get("name").await?;
    println!("Value: {}", String::from_utf8_lossy(&value));
     
    // List all keys
    let keys = client.list_keys().await?;
    println!("Keys: {:?}", keys);
     
    // Delete a key
    client.delete("name").await?;
     
    Ok(())
}

ยงโœจ Features

  • Async/Await - Built on Tokio for high-performance async I/O
  • Connection Pooling - Efficient connection management and reuse
  • Type-Safe - Full Rust type safety and error handling
  • All Operations - PING, SET, GET, DELETE, LIST commands
  • CLI Tool - Command-line interface included (veddb-cli)

ยง๐Ÿ“– Usage Examples

ยงConnection Pooling

use veddb_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client with connection pool (10 connections)
    let client = Client::with_pool_size("127.0.0.1:50051", 10).await?;
     
    // Connections are automatically managed
    client.set("key1", "value1").await?;
    client.set("key2", "value2").await?;
     
    Ok(())
}

ยงWorking with Binary Data

use veddb_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::connect("127.0.0.1:50051").await?;
     
    // Store binary data
    let data = vec![0x01, 0x02, 0x03, 0x04];
    client.set("binary_key", &data).await?;
     
    // Retrieve binary data
    let retrieved = client.get("binary_key").await?;
    assert_eq!(retrieved, data);
     
    Ok(())
}

ยงError Handling

use veddb_client::{Client, Error};

#[tokio::main]
async fn main() {
    let client = Client::connect("127.0.0.1:50051").await.unwrap();
     
    match client.get("nonexistent_key").await {
        Ok(value) => println!("Found: {:?}", value),
        Err(Error::Server(msg)) if msg.contains("NotFound") => {
            println!("Key not found");
        }
        Err(e) => eprintln!("Error: {}", e),
    }
}

ยง๐Ÿ–ฅ๏ธ CLI Tool

This crate includes veddb-cli, a command-line interface for VedDB:

# Ping server
veddb-cli ping

# Set a key
veddb-cli kv set name Alice

# Get a key
veddb-cli kv get name

# List all keys
veddb-cli kv list

# Delete a key
veddb-cli kv del name

ยง๐Ÿ”Œ Protocol

VedDB uses a simple binary protocol over TCP:

  • Little-endian encoding for all integers
  • Command format: 24-byte header + payload
  • Response format: 20-byte header + payload

ยงSupported Operations

OpCodeCommandDescription
0x01PINGHealth check
0x02SETStore key-value pair
0x03GETRetrieve value by key
0x04DELETERemove key
0x09LISTList all keys

ยง๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Re-exportsยง

pub use bytes;

Structsยง

Client
A client for interacting with a VedDB server
ClientBuilder
A builder for configuring and creating a client
Command
Command structure
Connection
A connection to a VedDB server
ConnectionPool
A connection pool for managing multiple connections to a VedDB server
Response
Response structure

Enumsยง

Error
Error type for VedDB client operations
StatusCode
Response status codes

Type Aliasesยง

Result
Custom result type for VedDB operations