RocksDb.Net

A modern C# wrapper for RocksDb, the high-performance embedded key-value store developed by Meta. Built on .NET's LibraryImport source generator with zero-copy spans and deterministic disposal.

Install

dotnet add package RocksDb.Net

The native binaries come from the RocksDb.Net.Runtimes package, which the main package depends on.

Targets .NET 8.0 and 10.0, and runs on any later .NET.

Quick start

using RocksDbNet;

// No `using` on the options: Open takes ownership of them.
var options = new DbOptions { CreateIfMissing = true };
using var db = RocksDb.Open(options, "mydb");

db.Put("key", "value");
string? value = db.GetString("key");

RocksDb.Open takes ownership of the DbOptions it is given, so do not reuse that instance afterwards.

Where to go next

  • API reference for the full surface, generated from the source.
  • Your first database if you have not used RocksDb before: keys and values, iteration, batches, durability and column families.
  • Transactions for reading and writing under concurrency: pessimistic locking, optimistic conflict detection and the retry it needs, and two-phase commit for work that must survive a crash.
  • Ownership and lifetime for what owns which native handle. Worth reading before attaching a comparator or logger, because the rules are not uniform.
  • Writing callbacks for comparators, merge operators, loggers and event listeners, and Compaction filters for transforming data as it is rewritten.
  • Callbacks and exceptions for what happens when one of those throws, which differs per callback and in one case terminates the process.
  • Logging and metrics for RocksDb's info log through ILogger, its statistics and key properties as System.Diagnostics.Metrics instruments, and what statistics cost.
  • Compared with rocksdb-sharp if you are choosing between the two .NET bindings, or moving from one to the other.
  • Samples in the repository, one per feature area.

Versioning

The package version is <RocksDbVersion>.<Revision>, so 11.12.0.1 wraps RocksDb 11.12.0. Breaking changes land only when the RocksDb version changes; a revision bump alone never breaks compatibility. See the changelog.