Set up Redis in the AppHost
Dette indhold er ikke tilgængeligt i dit sprog endnu.
This article is the reference for the Aspire Redis Hosting integration. It enumerates the AppHost APIs — with examples for both AppHost.cs and apphost.ts — that you use to model a Redis resource in your AppHost project.
If you’re new to the Redis integration, start with the Get started with Redis integrations guide. For how consuming apps read the connection information this page exposes, see Connect to Redis.
Installation
Section titled “Installation”To start building an Aspire app that uses Redis, install the 📦 Aspire.Hosting.Redis NuGet package:
aspire add redisLearn more about aspire add in the command reference.
Or, choose a manual installation approach:
#:package Aspire.Hosting.Redis@*<PackageReference Include="Aspire.Hosting.Redis" Version="*" />aspire add redisLearn more about aspire add in the command reference.
This updates your aspire.config.json with the Redis hosting integration package:
{ "packages": { "Aspire.Hosting.Redis": "13.3.0" }}Add Redis resource
Section titled “Add Redis resource”Once you’ve installed the hosting integration in your AppHost project, you can add a Redis resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache");
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice") .WithReference(cache);
// After adding all resources, run the app...import { createBuilder } from './.modules/aspire.js';
const builder = await createBuilder();
const cache = await builder.addRedis("cache");
await builder.addNodeApp("api", "./api", "index.js") .withReference(cache);
// After adding all resources, run the app...-
When Aspire adds a container image to the AppHost, as shown in the preceding example with the
docker.io/library/redisimage, it creates a new Redis instance on your local machine. -
The Redis resource is configured with a randomly generated password by default. To set an explicit password, see Add Redis resource with parameters.
-
The AppHost reference call configures a connection in the consuming project named after the referenced Redis resource, such as
cachein the preceding example.
Add Redis resource with data volume
Section titled “Add Redis resource with data volume”Add a data volume to the Redis resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithDataVolume(isReadOnly: false);
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withDataVolume(options?: { name?: string; isReadOnly?: boolean;}): RedisResource (+1 overload)
Adds a data volume with persistence
withDataVolume({ isReadOnly?: boolean | undefined
isReadOnly: false });
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...The data volume is used to persist Redis data outside the lifecycle of its container. The data volume is mounted at the /data path in the Redis container, and when a name parameter isn’t provided, the name is generated at random. Calling WithDataVolume (or withDataVolume) also enables Redis persistence so the in-memory state survives container restarts. For more information on data volumes and details on why they’re preferred over bind mounts, see Docker docs: Volumes.
Add Redis resource with data bind mount
Section titled “Add Redis resource with data bind mount”Add a data bind mount to the Redis resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithDataBindMount( source: @"C:\Redis\Data", isReadOnly: false);
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withDataBindMount(source: string, options?: { isReadOnly?: boolean;}): RedisResource (+1 overload)
Adds a data bind mount with persistence
withDataBindMount("C:\\Redis\\Data", { isReadOnly?: boolean | undefined
isReadOnly: false });
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...Data bind mounts rely on the host machine’s filesystem to persist Redis data across container restarts. The data bind mount is mounted at the C:\Redis\Data on Windows (or /Redis/Data on Unix) path on the host machine in the Redis container. As with WithDataVolume, this call also enables persistence. For more information on data bind mounts, see Docker docs: Bind mounts.
Add Redis resource with persistence
Section titled “Add Redis resource with persistence”To configure Redis snapshot persistence explicitly, call WithPersistence (or withPersistence) alongside a data volume or bind mount:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithDataVolume() .WithPersistence( interval: TimeSpan.FromMinutes(5), keysChangedThreshold: 100);
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withDataVolume(options?: { name?: string; isReadOnly?: boolean;}): RedisResource (+1 overload)
Adds a data volume with persistence
withDataVolume();await const cache: RedisResource
cache.RedisResource.withPersistence(options?: { interval?: timespan; keysChangedThreshold?: number;}): RedisResource (+1 overload)
Configures Redis persistence
withPersistence({ interval?: timespan | undefined
interval: 5 * 60 * 1000, keysChangedThreshold?: number | undefined
keysChangedThreshold: 100,});
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...The preceding code adds explicit persistence to the Redis resource by snapshotting data at the configured interval whenever the configured number of keys changes. The C# AppHost accepts a TimeSpan for interval; the TypeScript AppHost accepts the same value as milliseconds.
Add Redis resource with parameters
Section titled “Add Redis resource with parameters”When you want to explicitly provide the port and password used by the Redis container, you can pass them as parameters:
var builder = DistributedApplication.CreateBuilder(args);
var password = builder.AddParameter("password", secret: true);
var cache = builder.AddRedis("cache", port: 6379, password: password);
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const password: ParameterResource
password = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addParameter(name: string, options?: { value?: string; publishValueAsDefault?: boolean; secret?: boolean;}): ParameterResource (+1 overload)
Adds a parameter resource
addParameter("password", { secret?: boolean | undefined
secret: true });
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache", { port?: number | undefined
port: 6379, password?: string | ParameterResource | undefined
password });
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...When no password parameter is provided, Aspire generates a strong password automatically using the CreateDefaultPasswordParameter method.
Add Redis resource with Redis Insight
Section titled “Add Redis resource with Redis Insight”Redis Insight is a free graphical interface for analyzing Redis data. Add it to the Redis resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithRedisInsight();
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withRedisInsight(options?: { configureContainer?: (obj: RedisInsightResource) => Promise<void>; containerName?: string;}): RedisResource (+1 overload)
Adds Redis Insight management UI
withRedisInsight();
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...The preceding code adds a container based on the docker.io/redis/redisinsight image. The Redis Insight UI is available from the Aspire dashboard and connects automatically to the Redis resource.
Configure Redis Insight host port
Section titled “Configure Redis Insight host port”To configure the host port for the Redis Insight container, use the configureContainer callback as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithRedisInsight(redisInsight => redisInsight.WithHostPort(8001));
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withRedisInsight(options?: { configureContainer?: (obj: RedisInsightResource) => Promise<void>; containerName?: string;}): RedisResource (+1 overload)
Adds Redis Insight management UI
withRedisInsight({ configureContainer?: ((obj: RedisInsightResource) => Promise<void>) | undefined
configureContainer: async redisInsight: RedisInsightResource
redisInsight => { await redisInsight: RedisInsightResource
redisInsight.RedisInsightResource.withHostPort(port: number | null): RedisInsightResource
Sets the host port for Redis Insight
withHostPort(8001); }});
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...The preceding code adds and configures the host port for the Redis Insight container. The host port is otherwise randomly assigned.
Add Redis resource with Redis Commander
Section titled “Add Redis resource with Redis Commander”Redis Commander is a Node.js web application for viewing, editing, and managing a Redis database. Add it to the Redis resource as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithRedisCommander();
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withRedisCommander(options?: { configureContainer?: (obj: RedisCommanderResource) => Promise<void>; containerName?: string;}): RedisResource (+1 overload)
Adds Redis Commander management UI
withRedisCommander();
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...The preceding code adds a container based on the docker.io/rediscommander/redis-commander image. The Redis Commander UI is available from the Aspire dashboard and connects automatically to the Redis resource.
Configure Redis Commander host port
Section titled “Configure Redis Commander host port”To configure the host port for the Redis Commander container, use the configureContainer callback as shown in the following examples:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithRedisCommander(redisCommander => redisCommander.WithHostPort(8081));
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");await const cache: RedisResource
cache.RedisResource.withRedisCommander(options?: { configureContainer?: (obj: RedisCommanderResource) => Promise<void>; containerName?: string;}): RedisResource (+1 overload)
Adds Redis Commander management UI
withRedisCommander({ configureContainer?: ((obj: RedisCommanderResource) => Promise<void>) | undefined
configureContainer: async redisCommander: RedisCommanderResource
redisCommander => { await redisCommander: RedisCommanderResource
redisCommander.RedisCommanderResource.withHostPort(port: number | null): RedisCommanderResource
Sets the host port for Redis Commander
withHostPort(8081); }});
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache);
// After adding all resources, run the app...The preceding code adds and configures the host port for the Redis Commander container. The host port is otherwise randomly assigned.
Add Redis resource with clear command
Section titled “Add Redis resource with clear command”The WithClearCommand method adds a CLEAR command button to the Aspire dashboard for the Redis resource. When clicked, it flushes all keys from the Redis database, which is useful during development to reset cache state without restarting the container.
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithClearCommand();
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...Pass custom environment variables
Section titled “Pass custom environment variables”By default, Aspire injects the Redis connection information using variable names derived from the resource name (for example, CACHE_URI, CACHE_HOST, CACHE_PORT, CACHE_PASSWORD). If your consuming app expects a different set of environment variable names, pass individual connection properties from the AppHost:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache");
var app = builder.AddExecutable("my-app", "node", "app.js", ".") .WithReference(cache) .WithEnvironment(context => { context.EnvironmentVariables["REDIS_HOST"] = cache.Resource.PrimaryEndpoint.Property(EndpointProperty.Host); context.EnvironmentVariables["REDIS_PORT"] = cache.Resource.PrimaryEndpoint.Property(EndpointProperty.Port); context.EnvironmentVariables["REDIS_PASSWORD"] = cache.Resource.PasswordParameter; });
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder, type EndpointProperty = "Url" | "Host" | "IPV4Host" | "Port" | "Scheme" | "TargetPort" | "HostAndPort" | "TlsEnabled"const EndpointProperty: { readonly Url: "Url"; readonly Host: "Host"; readonly IPV4Host: "IPV4Host"; readonly Port: "Port"; readonly Scheme: "Scheme"; readonly TargetPort: "TargetPort"; readonly HostAndPort: "HostAndPort"; readonly TlsEnabled: "TlsEnabled";}
Enum Aspire.Hosting.ApplicationModel.EndpointProperty
EndpointProperty } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const cache: RedisResource
cache = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addRedis(name: string, options?: { port?: number; password?: string | ParameterResource;}): RedisResource (+1 overload)
Adds a Redis container resource
addRedis("cache");const const cacheEndpoint: EndpointReference
cacheEndpoint = await const cache: RedisResource
cache.RedisResource.primaryEndpoint: () => Promise<EndpointReference>
Gets the PrimaryEndpoint property
primaryEndpoint();const const cacheHost: EndpointReferenceExpression
cacheHost = await const cacheEndpoint: EndpointReference
cacheEndpoint.EndpointReference.property(property: EndpointProperty): EndpointReferenceExpression
Gets the specified property expression of the endpoint
property(const EndpointProperty: { readonly Url: "Url"; readonly Host: "Host"; readonly IPV4Host: "IPV4Host"; readonly Port: "Port"; readonly Scheme: "Scheme"; readonly TargetPort: "TargetPort"; readonly HostAndPort: "HostAndPort"; readonly TlsEnabled: "TlsEnabled";}
Enum Aspire.Hosting.ApplicationModel.EndpointProperty
EndpointProperty.type Host: "Host"
Host);const const cachePort: EndpointReferenceExpression
cachePort = await const cacheEndpoint: EndpointReference
cacheEndpoint.EndpointReference.property(property: EndpointProperty): EndpointReferenceExpression
Gets the specified property expression of the endpoint
property(const EndpointProperty: { readonly Url: "Url"; readonly Host: "Host"; readonly IPV4Host: "IPV4Host"; readonly Port: "Port"; readonly Scheme: "Scheme"; readonly TargetPort: "TargetPort"; readonly HostAndPort: "HostAndPort"; readonly TlsEnabled: "TlsEnabled";}
Enum Aspire.Hosting.ApplicationModel.EndpointProperty
EndpointProperty.type Port: "Port"
Port);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("my-app", "./app", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const cache: RedisResource
cache) .ExecutableResource.withEnvironment(name: string, value: string | IResourceWithConnectionString | IValueProvider): NodeAppResource
Sets an environment variable
withEnvironment("REDIS_HOST", const cacheHost: EndpointReferenceExpression
cacheHost) .ExecutableResource.withEnvironment(name: string, value: string | IResourceWithConnectionString | IValueProvider): NodeAppResource
Sets an environment variable
withEnvironment("REDIS_PORT", const cachePort: EndpointReferenceExpression
cachePort) .ExecutableResource.withEnvironment(name: string, value: string | IResourceWithConnectionString | IValueProvider): NodeAppResource
Sets an environment variable
withEnvironment("REDIS_PASSWORD", await const cache: RedisResource
cache.RedisResource.passwordParameter: () => Promise<ParameterResource>
Gets the PasswordParameter property
passwordParameter());
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();Connect to an existing Redis instance
Section titled “Connect to an existing Redis instance”In C#, call AsExisting instead of AddRedis to reference an externally managed Redis instance:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .AsExisting(connectionStringParameter: builder.AddParameter("cache-cs", secret: true));
var exampleProject = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
// After adding all resources, run the app...The TypeScript AppHost doesn’t currently expose an asExisting(...) API for Redis. To connect to an existing Redis instance from a TypeScript AppHost, use builder.addConnectionString(...) with a parameter and reference that connection string from your consuming apps instead.
Connection properties
Section titled “Connection properties”For the full reference of Redis connection properties — and how consuming apps in C#, TypeScript, Python, and Go read them — see Connect to Redis.
Hosting integration health checks
Section titled “Hosting integration health checks”The Redis hosting integration automatically adds a health check for the Redis resource. The health check verifies that the Redis instance is running and that a connection can be established to it.
The hosting integration relies on the 📦 AspNetCore.HealthChecks.Redis NuGet package.