Home

Awesome

redb

CI Crates.io Documentation License dependency status

A simple, portable, high-performance, ACID, embedded key-value store.

redb is written in pure Rust and is loosely inspired by lmdb. Data is stored in a collection of copy-on-write B-trees. For more details, see the design doc

use redb::{Database, Error, ReadableTable, TableDefinition};

const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data");

fn main() -> Result<(), Error> {
    let db = Database::create("my_db.redb")?;
    let write_txn = db.begin_write()?;
    {
        let mut table = write_txn.open_table(TABLE)?;
        table.insert("my_key", &123)?;
    }
    write_txn.commit()?;

    let read_txn = db.begin_read()?;
    let table = read_txn.open_table(TABLE)?;
    assert_eq!(table.get("my_key")?.unwrap().value(), 123);

    Ok(())
}

Status

redb is undergoing active development, and should be considered beta quality. The file format is stable, but redb has not been widely deployed in production systems (at least to my knowledge).

Features

Development

To run all the tests and benchmarks a few extra dependencies are required:

Benchmarks

redb has similar performance to other top embedded key-value stores such as lmdb and rocksdb

redblmdbrocksdbsledsanakirja
bulk load2792ms1115ms5610ms5005ms1161ms
individual writes462ms1119ms1097ms957ms662ms
batch writes2568ms2247ms1344ms1622ms2713ms
random reads988ms558ms3469ms1509ms678ms
random reads962ms556ms3377ms1425ms671ms
random range reads2534ms985ms6058ms4670ms1089ms
random range reads2493ms998ms5801ms4665ms1119ms
random reads (4 threads)344ms141ms1247ms424ms266ms
random reads (8 threads)192ms72ms673ms230ms620ms
random reads (16 threads)131ms47ms476ms148ms3500ms
random reads (32 threads)118ms44ms412ms129ms4313ms
removals2184ms784ms2451ms2047ms1344ms

Source code for benchmark here. Results collected on a Ryzen 5900X with Samsung 980 PRO NVMe.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.