RocksDb.Net
11.0.4.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package RocksDb.Net --version 11.0.4.1
NuGet\Install-Package RocksDb.Net -Version 11.0.4.1
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.1" />
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.1" />
<PackageReference Include="RocksDb.Net" />
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.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RocksDb.Net, 11.0.4.1"
#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.1
#: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.1
#tool nuget:?package=RocksDb.Net&version=11.0.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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.hheader - Modern .NET — targets .NET 10, uses
LibraryImport,ReadOnlySpan<byte>, andref structiterators - Idiomatic C# API —
IDisposablehandles, properties, string overloads, LINQ-compatible iterators - Column families — create, drop, and operate on multiple column families
- Merge operators — built-in
UInt64Addand custom merge operator support - Compaction filters — filter or transform key-value pairs during compaction
- Transactions —
WriteBatchandWriteBatchWithIndexfor atomic multi-key operations - Backups & checkpoints —
BackupEngineandCheckpointfor 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.Runtimespackage
Requirements
- .NET 10 SDK (or later)
- RocksDB native binaries (provided by the
RocksDb.Net.RuntimesNuGet package)
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");
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
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 |
|---|---|
| Simple | 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 tools/NativeMethodsGenerator -- \
--version 11.0.4 \
--output RocksDb.Net/Native/NativeMethods.g.cs
License
See LICENSE for details.
| Product | Versions 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.
-
net10.0
- RocksDb.Net.Runtimes (>= 11.0.4.3)
-
net8.0
- RocksDb.Net.Runtimes (>= 11.0.4.3)
-
net9.0
- RocksDb.Net.Runtimes (>= 11.0.4.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
<a href="https://github.com/zcsizmadia/RocksDb.Net/releases">Release Notes</a>