Redis® support for Aspire.
$ dotnet add package Aspire.Hosting.RedisProvides extension methods and resource definitions for an Aspire AppHost to configure a Redis resource.
In your AppHost project, install the Aspire Redis Hosting library with NuGet:
dotnet add package Aspire.Hosting.Redis
Then, in the AppHost.cs file of AppHost, add a Redis resource and consume the connection using the following methods:
var redis = builder.AddRedis("redis");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(redis);
When you reference a Redis resource using WithReference, the following connection properties are made available to the consuming project:
The Redis resource exposes the following connection properties:
| Property Name | Description |
|---|---|
Host | The hostname or IP address of the Redis server |
Port | The port number the Redis server is listening on |
Password | The password for authentication |
Uri | The connection URI, with the format redis://:{Password}@{Host}:{Port} |
Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called db1 becomes DB1_URI.
https://github.com/dotnet/aspire
*Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd.