StackRedis.Uri 1.0.1

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

StackRedis.Uri

A .NET 8 class library that parses redis:// and rediss:// URI strings into StackExchange.Redis ConfigurationOptions, with a ready-made Redis service and ASP.NET Core DI registration. Works with any Redis provider — Upstash, Redis Cloud, Fly.io, self-hosted, etc.


Installation

dotnet add package StackRedis.Uri

Configuration

Add the following to your appsettings.json:

"RedisConfig": {
  "ConnectionString": "redis://default:your-password@your-host:6379"
}

Use rediss:// and port 6380 for TLS connections (e.g. Upstash over TLS).

Scheme Description
redis:// Plain TCP connection
rediss:// TLS/SSL connection (TLS 1.2 + 1.3 enabled automatically)

URI format: redis[s]://[username]:[password]@[host]:[port]


Registration

From configuration section

// Program.cs
builder.Services.AddRedisFromUri(builder.Configuration.GetSection("RedisConfig"));

From a URI string directly

builder.Services.AddRedisFromUri("rediss://default:password@host:6380");

Lazy connection (connects on first use)

builder.Services.AddRedisFromUriLazy(builder.Configuration.GetSection("RedisConfig"));
// or
builder.Services.AddRedisFromUriLazy("rediss://default:password@host:6380");

All overloads register the following as singletons:

  • IConnectionMultiplexer
  • IDatabase
  • IRedisService

Usage

Inject IRedisService

public class MyService(IRedisService redis)
{
    public async Task CacheUserAsync(string userId, string data)
    {
        await redis.SetStringAsync($"user:{userId}", data, expirationMinutes: 60);
    }

    public async Task<string?> GetUserAsync(string userId)
    {
        return await redis.GetStringAsync($"user:{userId}");
    }

    public async Task InvalidateUserAsync(string userId)
    {
        await redis.DeleteAsync($"user:{userId}");
    }
}

Inject IConnectionMultiplexer (advanced)

public class MyService(IConnectionMultiplexer redis)
{
    public async Task PublishAsync(string channel, string message)
    {
        var pub = redis.GetSubscriber();
        await pub.PublishAsync(channel, message);
    }
}

API Reference

IRedisService

Method Description
SetStringAsync(key, value, expirationMinutes) Stores a string value with a TTL
GetStringAsync(key) Returns the value, or null if missing or expired
DeleteAsync(key) Deletes a single key
ExistsAsync(key) Returns true if the key exists
ExistsBatchAsync(keys) Returns a HashSet<string> of which keys exist (batched pipeline)
DeleteByPrefixAsync(prefix) Deletes all keys matching a prefix (e.g. "user:")

RedisUriParser

Parses a URI string directly into ConfigurationOptions without DI.

var options = RedisUriParser.Parse("rediss://default:password@host:6380");

// With custom overrides
var options = RedisUriParser.Parse("rediss://default:password@host:6380", opt =>
{
    opt.ConnectTimeout = 5000;
    opt.SyncTimeout = 1000;
});

RedisConnectionFactory

Creates a ConnectionMultiplexer directly without DI.

// Async
var connection = await RedisConnectionFactory.ConnectAsync("rediss://default:password@host:6380");

// Sync
var connection = RedisConnectionFactory.Connect("rediss://default:password@host:6380");

IDatabase db = connection.GetDatabase();

RedisConfig

Options class for binding Redis connection settings from appsettings.json. Use this when you want to bind configuration manually without the DI extensions.

Property Type Default Description
ConnectionString string "" The redis:// or rediss:// URI

Manual binding example:

var redisConfig = new RedisConfig();
builder.Configuration.GetSection("RedisConfig").Bind(redisConfig);

var options = RedisUriParser.Parse(redisConfig.ConnectionString);

IOptions<RedisConfig> pattern:

// Program.cs
builder.Services.Configure<RedisConfig>(builder.Configuration.GetSection("RedisConfig"));

// Your service
public class MyService(IOptions<RedisConfig> redisConfig)
{
    private readonly string _uri = redisConfig.Value.ConnectionString;
}

Default Connection Settings

Setting Value
AbortOnConnectFail false
ConnectTimeout 15 000 ms
SyncTimeout 3 000 ms
AsyncTimeout 3 000 ms
ConnectRetry 3
ReconnectRetryPolicy Exponential backoff (base 5 000 ms)
KeepAlive 60 s
TLS (rediss://) TLS 1.2 + TLS 1.3

All defaults can be overridden via the optional configure delegate on any registration method.


Requirements

  • .NET 8
  • A Redis instance accessible via a redis:// or rediss:// URI
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 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 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. 
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
1.0.1 140 3/16/2026
1.0.0 114 3/9/2026