Skip to main content
net8.0net9.0net10.0

An Azure Cache for Redis® client that integrates with Aspire, including Azure AD authentication, health checks, logging and telemetry.

Published
Apr 8, 2026
6mo ago
Total Downloads
147.3K
147,288

Install

dotnet add package Aspire.Microsoft.Azure.StackExchangeRedis --version 13.2.2-preview.1.26207.2
ProductVersions
.NET
net10.0net8.0net9.0

README

Aspire.Microsoft.Azure.StackExchangeRedis library

Configures the Aspire.StackExchange.Redis package with Azure AD authentication when connecting to an Azure Cache for Redis instance.

Getting started

Prerequisites

Differences with Aspire.StackExchange.Redis

The Aspire.Microsoft.Azure.StackExchangeRedis library is a wrapper around the Aspire.StackExchange.Redis library that provides additional features for connecting to Azure Cache for Redis with Azure AD authentication. If you don't need these features, you can use the Aspire.StackExchange.Redis library instead.

At runtime the client integration will use Azure AD authentication when a credential is configured, allowing passwordless authentication with Azure Cache for Redis.

Install the package

Install the Aspire Azure StackExchange.Redis library with NuGet:

dotnet add package Aspire.Microsoft.Azure.StackExchangeRedis

Usage example

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

builder.AddRedisClientBuilder("cache")
    .WithAzureAuthentication();

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

private readonly IConnectionMultiplexer _cache;

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

Using keyed services

You can also register keyed Redis clients using the keyed services pattern:

builder.AddKeyedRedisClientBuilder("cache")
    .WithAzureAuthentication();

Then retrieve the keyed service:

public ProductsController([FromKeyedServices("cache")] IConnectionMultiplexer cache)
{
    _cache = cache;
}

Adding distributed caching and output caching

You can add distributed caching and output caching to the Redis client by chaining additional methods:

builder.AddRedisClientBuilder("cache")
    .WithAzureAuthentication()
    .WithDistributedCache()
    .WithOutputCache();

Configure Azure AD authentication

Use the WithAzureAuthentication method to establish a connection using Azure AD authentication. If no credential is provided, a default TokenCredential is created based on the current environment.

builder.AddRedisClientBuilder("cache")
    .WithAzureAuthentication(new ManagedIdentityCredential());

AppHost extensions

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

dotnet add package Aspire.Hosting.Azure.Redis

Then, in the Program.cs file of AppHost, register an Azure Cache for Redis instance and consume the connection using the following methods:

var redis = builder.AddAzureRedis("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.AddRedisClientBuilder("cache")
    .WithAzureAuthentication();

This will also require your Azure environment to be configured by following these instructions.

Additional documentation

Feedback & contributing

https://github.com/microsoft/aspire

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

Changes from Previous Version

No structural changes between v13.2.1-preview.1.26180.6 and v13.2.2-preview.1.26207.2.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.The published metadata declares 56 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.