cberner /redb

An embedded key-value database in pure Rust

★ 4,937⑂ 260👁 23⑃ 1,281● 399▤ 70
RustApache-2.0Created 2018-09-23www.redb.org
下载:4.6.04.6.0 ↓4.6.02026-11-13
+2
日增长
4,937
stars
260
forks
23
watchers
1,281
prs
399
issues
70
releases

README

redb

!CI





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

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

const TABLE: TableDefinition = TableDefinition::new("my_data");

fn main() - Result {
    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
Stable and maintained.

The file format is stable, and a reasonable effort will be made to provide an upgrade path if there
are any future changes to it.

 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
 Multi-process access to one database, with a single or several writer processes

 no_std

Turning off the std feature, with experimental-api-5 on, builds redb without the standard
library. It needs alloc, panic = "abort", and a target with atomic compare-and-swap -- Cortex-M3
and above, but not Cortex-M0. Embedded targets abort on panic by default. Tests always unwind, so
tests run on the host need the std feature, which a dev-dependency on redb can enable. There is no
filesystem, so storage is supplied by implementing StorageBackend, which reports failures with
BackendError::Other, and passing it to Builder::create_with_backend() or
Builder::open_read_only_with_backend(). The chrono_v0_4 and uuid features require std, and
cache_metrics requires a target with 64-bit atomics.

 Development

just and rootless
podman are required.
Toolchain setup, dependency vendoring, and cargo-deny checks may use network access without
compiling project dependencies. Other development recipes continue to run on
the host. Cargo build artifacts are cached in the redb-sandbox-target Podman
volume; remove that volume to force a clean sandbox build.

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

|                           | redb      | lmdb       | rocksdb        | fjall       | sqlite     |
|---------------------------|-----------|------------|----------------|-------------|------------|
| bulk load                 | 17063ms   | 9232ms | 13969ms        | 18619ms     | 15341ms    |
| individual writes         | 920ms | 1598ms     | 2432ms         | 3488ms      | 7040ms     |
| batch writes              | 1595ms    | 942ms      | 451ms          | 353ms   | 2625ms     |
| len()                     | 0ms   | 0ms    | 749ms          | 1181ms      | 30ms       |
| random reads      

Top issues

Latest release

4.6.0 v4.6.0 2026-11-13
Minor improvements
 A new database starts at 72 KiB instead of about 1 MiB, and grows as it is written to.

 Bug fixes
 Fix repair falling back to a commit slot that failed its checksum, which could open a damaged
  database as an empty one instead of returning StorageError::Corrupted.
 commit() returns CommitError::TransactionPoisoned when a table opened in the transaction was
  leaked, for example with mem::forget(), instead of committing a corrupted database.
 MultimapTable::insert() and MultimapTable::remove() poison the write transaction if the key
  or value type panics part way

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON