Configs2026年5月21日·1 分钟阅读

Redb — Simple Embedded Key-Value Store in Pure Rust

A lightweight, ACID-compliant embedded key-value database written in pure Rust with zero unsafe code and a B-tree based storage engine.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Redb Overview
通用 CLI 安装命令
npx tokrepo install eb969dda-5551-11f1-9bc6-00163e2b0d79

Introduction

Redb is an embedded key-value store written entirely in safe Rust. It was designed as a modern alternative to LMDB and sled, prioritizing correctness, simplicity, and safety. The codebase uses zero unsafe blocks, relying on Rust's type system and borrow checker to prevent memory bugs while still delivering competitive read and write performance.

What Redb Does

  • Provides ACID-compliant transactions with serializable isolation
  • Stores typed key-value pairs in named tables within a single database file
  • Supports range queries, prefix scans, and reverse iteration over ordered keys
  • Offers multimap tables where a single key can map to multiple values
  • Handles crash recovery automatically with no manual repair tools needed

Architecture Overview

Redb uses a copy-on-write B-tree for its core storage structure. Writes create new tree pages rather than modifying existing ones, and a two-phase commit ensures atomicity. The database file uses a custom allocator that tracks free pages for reuse. All I/O goes through Rust's standard library with no mmap or unsafe FFI, making the codebase auditable and safe by construction.

Self-Hosting & Configuration

  • Add redb as a Cargo dependency; no external services or build tools required
  • Create a database by specifying a file path; the file is created automatically
  • Define table schemas at compile time using the TableDefinition type
  • Configure cache size and durability mode through the Database builder API
  • Use in-memory mode for testing by creating a database without a file path

Key Features

  • Zero unsafe code provides strong memory safety guarantees
  • MVCC readers never block writers and vice versa
  • Typed tables catch key-value type mismatches at compile time
  • Multimap tables natively support one-to-many relationships
  • Savepoints allow rolling back to intermediate points within a transaction

Comparison with Similar Tools

  • sled — sled uses lock-free structures for concurrency; redb uses a simpler copy-on-write B-tree with zero unsafe code
  • LMDB — LMDB is C with memory-mapped I/O; redb is pure safe Rust with standard file I/O
  • RocksDB — RocksDB is a C++ LSM-tree engine; redb is a simpler B-tree store for moderate workloads
  • SQLite — SQLite is a relational database; redb is a lower-level key-value store with typed tables
  • bbolt — bbolt is a Go embedded database; redb is the Rust equivalent with a similar B-tree design

FAQ

Q: Is redb production-ready? A: Yes. Redb reached version 1.0 and later 2.0 with a stable API. It is used in production by several projects including the Ordinals Bitcoin indexer.

Q: How does redb compare to sled in performance? A: Redb is generally competitive with sled on read-heavy workloads and can be faster for write-heavy workloads due to its simpler architecture. Benchmarks vary by use case.

Q: Does redb support concurrent access from multiple threads? A: Yes. Multiple readers can run concurrently with a single writer. Readers see a consistent snapshot and are never blocked by writes.

Q: Can redb handle large datasets? A: Redb supports databases up to several terabytes. The B-tree structure provides logarithmic lookup times regardless of dataset size.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产