wedb_embed 0.1.0

Embedded Kvrocks-compatible storage engine for WeDb
Documentation

wedb_embed

Crates.io Documentation Rust Edition 2024

wedb_embed is a high-performance, disk-backed, multi-model storage engine built on top of the Fjall LSM-Tree engine. It provides zero-cost abstractions for complex Redis-compatible data structures, transaction capabilities, and metadata-aware key composition.


🚀 Features

  • Multi-Model Data Structures:
    • String: Raw KV, numerical float/int operations (incr, decr, increx, getdel, getset).
    • Bitmap & Bitfield: Segmented LSB bitmap allocation, arbitrary-width signed/unsigned bitfield manipulation (bitfield, bitfield_read_only).
    • Hash: Subkey encoding with versioning, per-field TTL expiration (hexpire, hgetdel, hrandfield).
    • List: Double-ended deque with fast index-based access, trimming, pop, and atomic move (lmove, lmove_m).
    • Set & Sorted Set (ZSet): Fast member lookup, score range iterators, set algebra (sdiffcard, sunioncard).
    • Stream: Stream entry indexing, consumer group metadata, and PEL tracking.
    • RedisJSON: Native JSON tree parsing with JSONPath query execution using sonic-rs.
    • Probabilistic Data Structures: Scalable Bloom filters, Cuckoo filters, T-Digest estimators, and HyperLogLog.
    • TimeSeries & Geospatial: Chunked timeseries compression and 2D Geohash spatial distance indexing.
  • Microsecond Read/Write Performance: Powered by Fjall LSM-Tree partition routing and memory-mapped block caches.
  • KeyComposer: Namespace and database isolation, slot calculation (CRC16), and internal key prefixing.
  • TTL Engine: High-resolution millisecond key and subkey expiration state machines.

📦 Installation

Add wedb_embed to your Cargo.toml:

cargo add wedb_embed

🛠️ Usage Example

use wedb_embed::{WeDb, Conf, Result};

fn main() -> Result<()> {
    // Open or create database
    let conf = Conf::new("./data/embed_demo");
    let db = WeDb::open(conf)?;

    // 1. String operations
    db.set(b"site:name", b"WeDb", &[])?;
    if let Some(val) = db.get(b"site:name")? {
        println!("Site name: {}", String::from_utf8_lossy(&val));
    }

    // 2. Hash operations with atomic delete
    db.hset(b"user:101", &[(b"name", b"Bob"), (b"role", b"Admin")])?;
    let deleted_val = db.hget(b"user:101", b"role")?;
    println!("Role: {:?}", deleted_val);

    // 3. List operations
    db.rpush(b"task_queue", &[b"task_1", b"task_2", b"task_3"])?;
    let popped = db.lpop(b"task_queue", 1)?;
    println!("Popped: {:?}", popped);

    // 4. Set card algebra
    db.sadd(b"group_a", &[b"u1", b"u2", b"u3"])?;
    db.sadd(b"group_b", &[b"u2", b"u3", b"u4"])?;
    let diff = db.sdiff(&[b"group_a", b"group_b"])?;
    println!("Diff elements: {:?}", diff);

    Ok(())
}

📜 License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.