Installation
Install the Redis hosting integration package in your AppHost project:Usage
Add Redis Resource
In your AppHost project (AppHost.cs), add a Redis resource:
Consume in Service
In your service project, reference the Redis resource using the client integration:Program.cs:
API Reference
AddRedis
Adds a Redis container to the application model.Parameters
name- The name of the resource. This name will be used as the connection string name when referenced in a dependency.port- The host port to bind the underlying container to. If null, a random port will be assigned.password- The parameter used to provide the password for the Redis resource. Ifnulla random password will be generated.
Returns
A reference to theIResourceBuilder<RedisResource>.
Remarks
StackExchange.Redis doesn’t support passwords with commas, so the default generated password will not contain special characters.Configuration Examples
Custom Port
Custom Password
Data Persistence with Volumes
Redis Commander Management Tool
Redis Insight Management Tool
Named Volumes
Bind Mounts
Persistence Configuration
Configure Redis to use AOF (Append Only File) persistence:Connection Properties
When you reference a Redis resource usingWithReference, the following connection properties are made available to the consuming project.
Redis Resource
| 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} |
Environment Variables
Aspire exposes each property as an environment variable named[RESOURCE]_[PROPERTY]. For instance:
- The
Uriproperty of a resource calledcachebecomesCACHE_URI - The
Hostproperty becomesCACHE_HOST
Health Checks
The Redis hosting integration includes built-in health checks. When a resource is referenced as a dependency usingWaitFor, the dependent resource will wait until the Redis resource is able to service requests.