RocksDb.Net 11.0.4.2

dotnet add package RocksDb.Net --version 11.0.4.2
                    
NuGet\Install-Package RocksDb.Net -Version 11.0.4.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RocksDb.Net" Version="11.0.4.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RocksDb.Net" Version="11.0.4.2" />
                    
Directory.Packages.props
<PackageReference Include="RocksDb.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RocksDb.Net --version 11.0.4.2
                    
#r "nuget: RocksDb.Net, 11.0.4.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RocksDb.Net@11.0.4.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RocksDb.Net&version=11.0.4.2
                    
Install as a Cake Addin
#tool nuget:?package=RocksDb.Net&version=11.0.4.2
                    
Install as a Cake Tool

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.

Features

  • Full RocksDb C API coverage — 1,000+ auto-generated P/Invoke bindings from the official rocksdb/c.h header
  • Modern .NET — targets .NET 10, uses LibraryImport, ReadOnlySpan<byte>, and ref struct iterators
  • Idiomatic C# APIIDisposable handles, properties, string overloads, LINQ-compatible iterators
  • Column families — create, drop, and operate on multiple column families
  • Merge operators — built-in UInt64Add and custom merge operator support
  • Compaction filters — filter or transform key-value pairs during compaction
  • TransactionsWriteBatch and WriteBatchWithIndex for atomic multi-key operations
  • Backups & checkpointsBackupEngine and Checkpoint for point-in-time snapshots
  • SST file ingestion — bulk-load data with SstFileWriter
  • Bloom/Ribbon filters — configurable filter policies for point lookups
  • Event listeners — observe flush, compaction, and background error events
  • Cross-platform — ships native binaries via the RocksDb.Net.Runtimes package

Requirements

Quick Start

Install

dotnet add package RocksDb.Net

Basic Usage

using RocksDbNet;

using var options = new DbOptions { CreateIfMissing = true };
using var db = RocksDb.Open(options, "mydb");

// Write
db.Put("hello", "world");

// Read
string? value = db.GetString("hello");
Console.WriteLine(value); // "world"

// Delete
db.Delete("hello");

Important lifetime note:

  • RocksDb.Open* takes ownership of the DbOptions instance you pass in.
  • After opening, do not reuse that same DbOptions instance for other operations (for example Destroy, Repair, or ListColumnFamilies).
  • If you need options again, create a new DbOptions (or Clone() before passing ownership).

For static utilities that do not open a DB handle (Destroy, Repair, ListColumnFamilies), ownership is not transferred; dispose those options yourself.

Iteration

using var iterator = db.NewIterator();
iterator.SeekToFirst();

foreach (var entry in iterator)
{
    Console.WriteLine($"{entry.CurrentKey} = {entry.CurrentValue}");
}

Column Families

using var options = new DbOptions
{
    CreateIfMissing = true,
    CreateMissingColumnFamilies = true
};

var descriptors = new List<ColumnFamilyDescriptor>
{
    new("default"),
    new("logs"),
    new("metrics")
};

using var db = RocksDb.Open(options, "mydb", descriptors);

var logsCf = db.GetColumnFamily("logs");
db.Put("entry1", "data", logsCf);

WriteBatch (Atomic Operations)

using var batch = new WriteBatch();
batch.Put("key1", "val1")
     .Put("key2", "val2")
     .Delete("old_key");

db.Write(batch);

Snapshots

using var snapshot = db.NewSnapshot();
using var readOpts = new ReadOptions();
readOpts.SetSnapshot(snapshot);

// Reads see the database state at snapshot time
string? val = db.GetString("key", readOptions: readOpts);

Merge Operators

// Built-in UInt64 addition
using var options = new DbOptions { CreateIfMissing = true };
options.SetUInt64AddMergeOperator();
using var db = RocksDb.Open(options, "counters");

db.Merge("visits", BitConverter.GetBytes(1UL));
db.Merge("visits", BitConverter.GetBytes(5UL));

ulong total = BitConverter.ToUInt64(db.Get("visits"));
// total == 6

Nested handle lifetime note:

  • MergeOperator, CompactionFilterFactory, and EventListener are transferred to native shared ownership when assigned to DbOptions.
  • Comparator, CompactionFilter, Logger, and RateLimiter are disposed with DbOptions.
  • In all cases, these objects must outlive the open RocksDb instance that uses them.

Backup & Restore

using var engine = BackupEngine.Open("backups");
engine.CreateNewBackup(db);

// Later: restore
engine.RestoreDbFromLatestBackup("restored_db");

SST File Ingestion

using var envOpts = new EnvOptions();
using var dbOpts = new DbOptions();
using var writer = SstFileWriter.Create(envOpts, dbOpts);

writer.Open("data.sst");
writer.Put("key1", "val1"); // Keys must be in sorted order
writer.Put("key2", "val2");
writer.Finish();

db.IngestExternalFile(new[] { "data.sst" });

Bloom Filters

using var tableOptions = new BlockBasedTableOptions();
tableOptions.SetFilterPolicy(FilterPolicy.CreateBloom(10));

using var options = new DbOptions { CreateIfMissing = true };
options.BlockBasedTableFactory = tableOptions;

using var db = RocksDb.Open(options, "filtered_db");

Samples

The Samples/ directory contains runnable examples:

Sample Description
Basic Basic open, put, get, delete
WriteBatchSample Atomic multi-key writes
IteratorSample Key-range scanning and seeking
ColumnFamilySample Working with column families
SnapshotSample Point-in-time consistent reads
MergeOperatorSample Custom and built-in merge operators
CompactionFilterSample Filtering keys during compaction
BackupAndCheckpointSample Backups and checkpoints
SstFileWriterSample Bulk-loading with SST files
BloomFilterSample Bloom and Ribbon filter policies
EventListenerSample Observing database events
ReadOnlyAndSecondarySample Read-only and secondary instances
TuningAndStatsSample Performance tuning and statistics

Run any sample with:

dotnet run --project Samples/Simple

Architecture

RocksDb.Net/
├── Native/
│   ├── NativeMethods.g.cs       # Auto-generated P/Invoke bindings (1,047 functions)
│   ├── NativeMethods.Helpers.cs  # Native library resolver and helpers
│   └── NativeResolver.cs         # Platform-specific library loading
├── RocksDb.cs                    # Main database class
├── DbOptions.cs                  # Database configuration options
├── WriteBatch.cs                 # Atomic write operations
├── Iterator.cs                   # Key-value iteration
├── ColumnFamilyHandle.cs         # Column family management
├── BackupEngine.cs               # Backup and restore
├── Checkpoint.cs                 # Database checkpoints
├── SstFileWriter.cs              # SST file creation for bulk loading
├── MergeOperator.cs              # Custom merge operators
├── CompactionFilter.cs           # Compaction-time key filtering
├── EventListener.cs              # Database event notifications
└── ...                           # Options, filters, cache, etc.

Building from Source

git clone https://github.com/user/RocksDb.Net.git
cd RocksDb.Net
dotnet build
dotnet test

The P/Invoke bindings in NativeMethods.g.cs are auto-generated from the RocksDb C header. To regenerate:

dotnet run --project NativeMethodsGenerator -- \
    --version 11.0.4 \
    --output RocksDb.Net/Native/NativeMethods.g.cs

License

See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.4.2 114 4/21/2026
11.0.4.1 104 4/19/2026