AzureRedisExtensions.AddAzureRedis Method

Definition

Caution

This method is obsolete and will be removed in a future version. Use AddAzureManagedRedis instead which provisions Azure Managed Redis.

Adds an Azure Cache for Redis resource to the application model.

[System.Obsolete("This method is obsolete and will be removed in a future version. Use AddAzureManagedRedis instead which provisions Azure Managed Redis.")]
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzureRedisCacheResource> AddAzureRedis(this Aspire.Hosting.IDistributedApplicationBuilder builder, string name);
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzureRedisCacheResource> AddAzureRedis(this Aspire.Hosting.IDistributedApplicationBuilder builder, string name);
[<System.Obsolete("This method is obsolete and will be removed in a future version. Use AddAzureManagedRedis instead which provisions Azure Managed Redis.")>]
static member AddAzureRedis : Aspire.Hosting.IDistributedApplicationBuilder * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzureRedisCacheResource>
static member AddAzureRedis : Aspire.Hosting.IDistributedApplicationBuilder * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzureRedisCacheResource>
<Extension()>
Public Function AddAzureRedis (builder As IDistributedApplicationBuilder, name As String) As IResourceBuilder(Of AzureRedisCacheResource)

Parameters

builder
IDistributedApplicationBuilder

The builder for the distributed application.

name
String

The name of the resource.

Returns

A reference to the IResourceBuilder<T> builder.

Attributes

Examples

The following example creates an Azure Cache for Redis resource and referencing that resource in a .NET project.

var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddAzureRedis("cache");

builder.AddProject<Projects.ProductService>()
    .WithReference(cache);

builder.Build().Run();

Remarks

By default, the Azure Cache for Redis resource is configured to use Microsoft Entra ID (Azure Active Directory) for authentication. This requires changes to the application code to use an azure credential to authenticate with the resource. See https://github.com/Azure/Microsoft.Azure.StackExchangeRedis for more information.

You can use the WithAccessKeyAuthentication(IResourceBuilder<AzureRedisCacheResource>, IResourceBuilder<IAzureKeyVaultResource>) method to configure the resource to use access key authentication.

The following example creates an Azure Cache for Redis resource and referencing that resource in a .NET project.
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddAzureRedis("cache");

builder.AddProject<Projects.ProductService>()
    .WithReference(cache);

builder.Build().Run();

Applies to