Redb 0.0.4

dotnet add package Redb --version 0.0.4
                    
NuGet\Install-Package Redb -Version 0.0.4
                    
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="Redb" Version="0.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Redb" Version="0.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Redb" />
                    
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 Redb --version 0.0.4
                    
#r "nuget: Redb, 0.0.4"
                    
#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 Redb@0.0.4
                    
#: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=Redb&version=0.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Redb&version=0.0.4
                    
Install as a Cake Tool

Redb.NET

redb (An embedded key-value database) bindings for .NET and Unity.

NuGet Releases license

English | 日本語

Overview

Redb.NET is a high-performance C# binding for redb, an embedded database implemented in Rust.

While SQLite is well-known as an embedded database, and LMDB or RocksDB as key-value databases, redb stands out as an excellent choice for its simplicity, stability, high performance, and support for concurrency.

Redb.NET provides a high-level binding for redb, offering an easy-to-use API for C#. The binding layer is carefully tuned for performance, ensuring no overhead.

Installation

Redb.NET includes native libraries, so the installation process differs significantly between .NET and Unity. Be careful not to confuse the two.

NuGet packages

Redb.NET requires .NET Standard 2.1 or higher. Packages are available on NuGet.

Package Description Latest Version
Redb The main package for Redb.NET. NuGet
Redb.SystemTextJson Extension package supporting serialization with System.Text.Json. NuGet
Redb.MessagePack Extension package supporting serialization with MessagePack for C#. NuGet

Unity

For Unity, all packages, including extension packages, can be installed via the Package Manager.

  1. Open the Package Manager from Window > Package Manager.
  2. Click the "+" button > Add package from git URL.
  3. Enter the URL for the corresponding package.
Package URL
Redb https://github.com/nuskey8/Redb.NET.git?path=src/Redb.Unity/Assets/Redb`
Redb.SystemTextJson https://github.com/nuskey8/Redb.NET.git?path=src/Redb.Unity/Assets/Redb.SystemTextJson`
Redb.MessagePack https://github.com/nuskey8/Redb.NET.git?path=src/Redb.Unity/Assets/Redb.MessagePack`

To use the extension packages, you need to separately add System.Text.Json or MessagePack using tools like NugetForUnity.

Due to differences in the binding implementation, the NuGet version of Redb.NET cannot be used in Unity. Always install it using the above method.

Platforms

Redb.NET supports the following platforms:

Platform Architecture Supported Notes
Windows x64
arm64
macOS x64
arm64 (Apple Silicon)
Linux x64
arm64
iOS arm64 ✅ (untested) (Unity only)
x64 ✅ (untested) (Unity only)
Android arm64 ✅ (untested) (Unity only)
armv7 ✅ (untested) (Unity only)
x86_64 ✅ (untested) (Unity only)

Quick Start

using Redb;

using var db = RedbDatabase.Create("test.redb", RedbDatabaseOptions.Default);

using (var tx = db.BeginWrite())
{
    using (var table = tx.OpenTable<string, int>("my_table"))
    {
        table.Insert("foo", 12);
        table.Insert("bar", 30);
    }

    tx.Commit();
}

using (var tx = db.BeginRead())
{
    using (var table = tx.OpenTable<string, int>("my_table"))
    {
        var foo = table.Get("foo");
        Console.WriteLine($"foo: {foo}");

        if (table.TryGet("bar", out var bar))
        {
            Console.WriteLine($"bar: {bar}");
        }
    }
}

Table API

You can open Table/ReadOnlyTable using OpenTable(). Both generic and non-generic types are available.

// generic table
using var table1 = tx.OpenTable<string, int>("my_table");

// non-generic table
using var table2 = tx.OpenTable("my_table");

In Table<TKey, TValue>/ReadOnlyTable<TKey, TValue>, the keys and values are strongly typed when reading and writing values.

table1.Insert("foo", 1);
int value = readOnlyTable1.Get("foo");

This is automatically serialized by the IRedbEncoding set in RedbDatabase. By default, primitive types and some other types are supported, but you can support any type by connecting a serializer. See the C# Serialization section for details.

In Table/ReadOnlyTable, you can directly read and write untyped binary data.

table2.Insert("foo"u8, "bar"u8);
RedbBlob blob = readOnlyTable2.Get("foo"u8);

RedbBlob is a struct that wraps a pointer on the Rust side. You can read values without overhead through this, but you must dispose of it with Dispose().

var span = blob.AsSpan();
span.CopyTo(buffer);
blob.Dispose();

Compaction

You can perform compaction by calling Compact().

db.Compact();

The default size of a redb database file is over 1MB, but compaction can reduce it to a few dozen KB.

C# Serialization

By default, binary (ReadOnlySpan<byte>), primitive types, Guid, DateTime, and TimeSpan can be used as keys or values. By connecting a serializer to the database, you can use any object as a key or value.

Currently, System.Text.Json and MessagePack for C# are supported.

using Redb;
using Redb.SystemTextJson;
// using Redb.MessagePack;

using var db = RedbDatabase.Create("test.redb", RedbDatabaseOptions.Default)
    .WithJsonSerializer(); // or .WithMessagePackSerializer();

using (var tx = db.BeginWrite())
{
    using (var table = tx.OpenTable<string, Person>("persons"))
    {
        table.Insert("alice", new Person("Alice", 18));
        table.Insert("bob", new Person("Bob", 30));
    }

    tx.Commit();
}

using (var tx = db.BeginRead())
{
    using (var table = tx.OpenTable<string, Person>("persons"))
    {
        var alice = table.Get("alice");
        var bob = table.Get("bob");
        Console.WriteLine(alice);
        Console.WriteLine(bob);
    }
}

record Person(string Name, int Age);

Supported Features

Redb.NET is currently in preview, and some features like MultimapTable are not yet implemented in the C# API. These are planned to be supported in the stable release.

License

This library is provided under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Redb:

Package Downloads
Redb.SystemTextJson

Redb System.Text.Json Encoder

Redb.MessagePack

Redb MessagePack Encoder

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.4 197 1/18/2026
0.0.3 158 1/14/2026
0.0.2 148 1/14/2026
0.0.1 110 1/14/2026