Skip to content
forked from cberner/redb

An embedded key-value database in pure Rust

License

Notifications You must be signed in to change notification settings

Icarus9913/redb

 
 

Repository files navigation

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. It may eat your data, and does not have any guarantees of file format stability :)

Features

  • Zero-copy, thread-safe, BTreeMap based API
  • Fully ACID-compliant transactions
  • MVCC support for concurrent readers & writer, without blocking
  • Crash-safe by default
  • Savepoints and rollbacks

Roadmap

The following features are planned before the 1.0 release

  • Stable file format

Benchmarks

redb is nearly as fast as lmdb, and faster than sled, on many benchmarks

+--------------------+--------------+------------+--------+---------+---------+
|                    | redb (1PC+C) | redb (2PC) | lmdb   | rocksdb | sled    |
+=============================================================================+
| bulk load          | 1770ms       | 1370ms     | 976ms  | 5263ms  | 4534ms  |
|--------------------+--------------+------------+--------+---------+---------|
| individual writes  | 227ms        | 381ms      | 388ms  | 701ms   | 642ms   |
|--------------------+--------------+------------+--------+---------+---------|
| batch writes       | 2346ms       | 2533ms     | 2136ms | 992ms   | 1395ms  |
|--------------------+--------------+------------+--------+---------+---------|
| large writes       | 8805ms       | 6532ms     | 7793ms | 21475ms | 37736ms |
|--------------------+--------------+------------+--------+---------+---------|
| random reads       | 734ms        | 734ms      | 642ms  | 5814ms  | 1514ms  |
|--------------------+--------------+------------+--------+---------+---------|
| random range reads | 832ms        | 834ms      | 712ms  | 6074ms  | 1826ms  |
|--------------------+--------------+------------+--------+---------+---------|
| removals           | 1281ms       | 1149ms     | 676ms  | 2481ms  | 1792ms  |
+--------------------+--------------+------------+--------+---------+---------+

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.

About

An embedded key-value database in pure Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 99.6%
  • Other 0.4%