Skip to main content

Crate redb

Crate redb 

Source
Expand description

§redb

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.

§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

§Example

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

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

fn main() -> Result<(), Error> {
    let file = tempfile::NamedTempFile::new().unwrap();
    let db = Database::create(file.path())?;
    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_owned("my_key")?.unwrap().value(), 123);

    Ok(())
}

§Crate features

  • std: enabled by default. Disable it to build redb as a no_std crate; see the README for what that mode requires and leaves out.

Modules§

backends

Structs§

AccessGuard
Scoped accessor to data in the database
AccessGuardMut
AccessGuardMutInPlace
Builder
Configuration builder of a redb Database.
CacheStats
Information regarding the usage of the in-memory cache
Cursor
A read-only cursor over a table, pointing at a gap between two entries.
CursorMut
A cursor over a Table, pointing at a gap between two entries, with support for inserting new entries into that gap and removing the entries around it.
Database
Opened redb database file
DatabaseStats
Informational storage stats about the database
ExtractIf
Legacy
T without the niche it declares: opens a table of Option<T> written before version 5.0.
MultimapRange
An iterator over the entries of a multimap table in a range of keys, in key order
MultimapTable
A multimap table
MultimapTableDefinition
Defines the name and types of a multimap table
MultimapValue
OccupiedEntry
A view into an occupied entry in a Table. It is part of the Entry enum.
OwnedAccessGuard
An AccessGuard which also keeps the transaction alive
OwnedMultimapRange
A MultimapRange which also keeps the transaction alive
OwnedMultimapValue
A MultimapValue which also keeps the transaction alive
OwnedRange
A Range which also keeps the transaction alive
Range
An iterator over the entries of a table in a range of keys, in key order
ReadOnlyDatabase
A redb database opened in read-only mode
ReadOnlyMultimapTable
A read-only multimap table
ReadOnlyTable
A read-only table
ReadOnlyUntypedMultimapTable
A read-only untyped multimap table
ReadOnlyUntypedTable
A read-only untyped table
ReadTransaction
A read-only transaction
RepairSession
Savepoint
A database savepoint
Table
A table containing key-value mappings
TableDefinition
Defines the name and types of a table
TableStats
Informational storage stats about a table
TableTypeMismatch
A table opened with key or value types other than the ones it is stored with. See TableError::TableTypeMismatch.
TypeDefinitionInfo
A key or value type whose fixed width differs from the one it is stored with. See TableError::TypeDefinitionChanged.
TypeName
UntypedMultimapTableHandle
UntypedTableHandle
VacantEntry
A view into a vacant entry in a Table. It is part of the Entry enum.
WriteTransaction
A read/write transaction

Enums§

BackendError
Errors reported by a crate::StorageBackend.
CommitError
Errors related to committing transactions
CompactionError
Errors related to compaction
CompactionMode
How thoroughly Database::compact() compacts the database file
ConcurrencyMode
How processes share a database: the regime a writer operates under. Whether a given handle writes is chosen by open() or open_read_only(), not by the mode.
CursorError
Errors related to cursors
DatabaseError
Errors related to opening a database
Durability
Entry
A view into a single entry in a Table, which may either be vacant or occupied.
Error
Superset of all other errors that can occur. Convenience enum so that users can convert all errors into a single type
SavepointError
Errors related to savepoints
SetDurabilityError
Errors related to setting a transaction’s durability
StorageError
General errors directly from the storage layer
TableError
Errors related to opening tables
TransactionError
Errors related to transactions

Traits§

Key
Trait which allows the type to be used as a key in a redb table
KeyRange
A range of keys, accepted by the range taking methods of a table
MultimapTableHandle
MutInPlaceValue
Implementing this trait indicates that the type can be mutated in-place as a &mut u8. This enables the .insert_reserve() method on Table
ReadableDatabase
ReadableMultimapTable
ReadableTable
ReadableTableMetadata
StorageBackend
Implements persistent storage for a database.
TableHandle
Value
Types that implement this trait can be used as values in a redb table

Type Aliases§

Result