Udostępnij za pośrednictwem


AzureRedisExtensions.AddAzureRedis Method

Definition

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

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzureRedisCacheResource> AddAzureRedis (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name);
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.

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>) method to configure the resource to use access key authentication.

Applies to