Aspire.StackExchange.Redis 8.2.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Aspire.StackExchange.Redis --version 8.2.2                
NuGet\Install-Package Aspire.StackExchange.Redis -Version 8.2.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="Aspire.StackExchange.Redis" Version="8.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aspire.StackExchange.Redis --version 8.2.2                
#r "nuget: Aspire.StackExchange.Redis, 8.2.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.
// Install Aspire.StackExchange.Redis as a Cake Addin
#addin nuget:?package=Aspire.StackExchange.Redis&version=8.2.2

// Install Aspire.StackExchange.Redis as a Cake Tool
#tool nuget:?package=Aspire.StackExchange.Redis&version=8.2.2                

Aspire.StackExchange.Redis library

Registers an IConnectionMultiplexer in the DI container for connecting to Redis®* server. Enables corresponding health check, logging, and telemetry.

Getting started

Prerequisites

  • Redis server and the server hostname for connecting a client.

Install the package

Install the .NET Aspire StackExchange Redis library with NuGet:

dotnet add package Aspire.StackExchange.Redis

Usage example

In the Program.cs file of your project, call the AddRedisClient extension method to register an IConnectionMultiplexer for use via the dependency injection container. The method takes a connection name parameter.

builder.AddRedisClient("cache");

You can then retrieve the IConnectionMultiplexer instance using dependency injection. For example, to retrieve the connection multiplexer from a Web API controller:

private readonly IConnectionMultiplexer _cache;

public ProductsController(IConnectionMultiplexer cache)
{
    _cache = cache;
}

See the StackExchange.Redis documentation for examples on using the IConnectionMultiplexer.

Configuration

The .NET Aspire StackExchange Redis component provides multiple options to configure the Redis connection based on the requirements and conventions of your project. Note that at least one host name is required to connect.

Use a connection string

When using a connection string from the ConnectionStrings configuration section, you can provide the name of the connection string when calling builder.AddRedisClient():

builder.AddRedisClient("myRedisConnectionName");

And then the connection string will be retrieved from the ConnectionStrings configuration section:

{
  "ConnectionStrings": {
    "myRedisConnectionName": "localhost:6379"
  }
}

See the Basic Configuration Settings of the StackExchange.Redis docs for more information on how to format this connection string.

Use configuration providers

The Redis component supports Microsoft.Extensions.Configuration. It loads the StackExchangeRedisSettings and ConfigurationOptions from configuration by using the Aspire:StackExchange:Redis key. Example appsettings.json that configures some of the options:

{
  "Aspire": {
    "StackExchange": {
      "Redis": {
        "ConfigurationOptions": {
          "ConnectTimeout": 3000,
          "ConnectRetry": 2
        },
        "DisableHealthChecks": true,
        "DisableTracing": false
      }
    }
  }
}

Use inline delegates

You can also pass the Action<StackExchangeRedisSettings> configureSettings delegate to set up some or all the options inline, for example to disable health checks from code:

builder.AddRedisClient("cache", settings => settings.DisableHealthChecks = true);

You can also setup the ConfigurationOptions using the Action<ConfigurationOptions> configureOptions delegate parameter of the AddRedisClient method. For example to set the connection timeout:

builder.AddRedisClient("cache", configureOptions: options => options.ConnectTimeout = 3000);

AppHost extensions

In your AppHost project, install the Aspire.Hosting.Redis library with NuGet:

dotnet add package Aspire.Hosting.Redis

Then, in the Program.cs file of AppHost, register a Redis server and consume the connection using the following methods:

var redis = builder.AddRedis("cache");

var myService = builder.AddProject<Projects.MyService>()
                       .WithReference(redis);

The WithReference method configures a connection in the MyService project named cache. In the Program.cs file of MyService, the redis connection can be consumed using:

builder.AddRedisClient("cache");

Additional documentation

Feedback & contributing

https://github.com/dotnet/aspire

*Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Aspire.StackExchange.Redis:

Package Downloads
Aspire.StackExchange.Redis.DistributedCaching

A Redis® implementation for IDistributedCache that integrates with Aspire, including health checks, logging, and telemetry.

Aspire.StackExchange.Redis.OutputCaching

A Redis® implementation for ASP.NET Core Output Caching that integrates with Aspire, including health checks, logging, and telemetry.

AICentral.Logging.PIIStripping

Package Description

AICentral.RateLimiting.DistributedRedis

Package Description

Arkmory.Orchestration.ServiceDefaults

Package Description

GitHub repositories (6)

Showing the top 5 popular GitHub repositories that depend on Aspire.StackExchange.Redis:

Repository Stars
dotnet/orleans
Cloud Native application framework for .NET
dotnet/eShop
A reference .NET application implementing an eCommerce site
abpframework/abp-samples
Sample solutions built with the ABP Framework
dotnet/aspire-samples
Azure-Samples/eShopOnAzure
A variant of https://github.com/dotnet/eShop that uses Azure services
Version Downloads Last updated
9.0.0 15,328 11/12/2024
9.0.0-rc.1.24511.1 9,862 10/15/2024
8.2.2 15,166 10/24/2024
8.2.1 23,565 9/26/2024
8.2.0 52,807 8/29/2024
8.1.0 44,089 7/23/2024
8.0.2 27,014 6/28/2024
8.0.1 43,998 5/21/2024
8.0.0 18,953 5/21/2024
8.0.0-preview.7.24251.11 9,551 5/7/2024
8.0.0-preview.6.24214.1 10,970 4/23/2024
8.0.0-preview.5.24201.12 12,272 4/9/2024
8.0.0-preview.4.24156.9 10,566 3/12/2024
8.0.0-preview.3.24105.21 15,616 2/13/2024
8.0.0-preview.2.23619.3 15,293 12/20/2023
8.0.0-preview.1.23557.2 13,541 11/14/2023