RESPite 2.9.99-gfe04f9c406

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

RESPite

RESPite is a high-performance low-level RESP (Redis, etc) library, used as the IO core for StackExchange.Redis v3+. It is also available for direct use from other places!

Getting Started

RESPite has two key primitives:

  • a connection, RespConnection.
  • a context, RespContext - which is a connection plus other local ambient context such as database, cancellation, etc.

The first thing we need, then, is to create a connection. There are many ways to do this, but to create a connection to the local default Redis instance:

using var conn = RespConnection.Create();
// ...

This gives us a single socket-based connection. Usually a connection is long-lived and used for a great many RESP operations, with the using here closing socket eventually.

Once we have a connection, we can start using it immediately, via the default context, from .Context. Usually, it is the context that we should be passing around, not a connection: the context has a connection plus local ambient configuration. So:

var ctx = conn.Context;

Once we have a context, we can use that to execute commands:

ctx.SomeOperation(...);

But: what is SomeOperation(...)? That's up to you.

Defining commands

The RESPite libary only handles the RESP layer - it doesn't add the methods associated with Redis (don't worry: RESPite.Redis does that - we're not animals!). However, in the general case where you want to add your own RESP methods, we can do exactly that. The easiest way is by letting the tools do the work for us:

static class MyCommands
{
    [RespOperation("incr")] // arg optional - it would assume "increment" if omitted
    public partial static int Increment(this in RespContext ctx, string key);

    [RespOperation("incrby")]
    public partial static int Increment(this in RespContext ctx, string key, int value);
}

Build-time tools will provide the implementation for us, including adding an async version. The code for this isn't difficult - simply: it is unnecessary, since in most cases the intent can be clearly understood. This avoids opportunities to fat-finger things (or get things wrong between the synchronous and asynchronous versions).

We can now use:

var x = ctx.Increment("mykey");
var y = await ctx.IncrementAsync("mykey", 42);

That's basically it. If you need more control over how non-trivial commands are formatted and parsed, APIs exist for that. But for most common scenarios: that's all we need.

Cancellation

Unusually, our IncrementAsync method does not have a CancellationToken cancellationToken = default parameter; instead, cancellation is conveyed in the context. This also means that cancellation works for both the synchronous and asynchronous versions! We can supply our own cancellation:

var ctx = conn.Context.WithCancellationToken(request.CancellationToken);
// use ctx for commands

Now ctx is not just the default context - it has the cancellation token we supplied, and it is used everywhere automatically! The RespContext type is cheap and allocation-free; it has no lifetime etc - it is just a bundle of state required for RESP operations. We can freely With... them:

var db = conn.Context.WithDatabase(4).WithCancellationToken(request.CancellationToken);
// use db for commands

If you're thinking "Wait - if RespContext carries cancellation, does WithCancellationToken(...) replace the cancellation, or combine the two cancellations?", then: have a cookie. The answer is "replace", but we can also combine multiple cancellations, noting that now we need to scope that to a lifetime:

using var lifetime = db.WithDatabase(4).WithCombineCancellationToken(anotherCancellationToken);
// use lifetime.Context for commands

This will automatically do the most appropriate thing based on whether neither, one, or both tokens are cancellable. We can do the same thing with a timeout:

using var lifetime = db.WithCombineTimeout(TimeSpan.FromSeconds(5));
// use lifetime.Context for commands

Note that this timeout applies to the lifetime, not individual operations (i.e. if we loop forever performing fast operations: it will still cancel after five seconds). From the name WithCombineTimeout, you can probably guess that this works in addition to the existing cancellation state. Help yourself to another cookie.

Summary

With the combination of RespConnection for the long-lived connection, RespContext for the transient local configuration (via various With* methods), and our automatically generated [RespCommand] methods: we can easily and efficiently talk to a range of RESP databases.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 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 was computed.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (4)

Showing the top 4 NuGet packages that depend on RESPite:

Package Downloads
RESPite.Bedrock

Package Description

RESPite.StackExchange.Redis

Package Description

RESPite.Resp

Low level RESP primitives.

RESPite.Resp.Client

Standard RESP command definitions using RESPite.Resp

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on RESPite:

Repository Stars
ServiceStack/ServiceStack
Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
ServiceStack/ServiceStack.Redis
.NET's leading C# Redis Client
Version Downloads Last Updated
2.9.99-gfe04f9c406 87 9/26/2025