Garnet client integration
Garnet is Redis-compatible, so you use the same Redis client packages. To get started, install the 📦 Aspire.StackExchange.Redis NuGet package:
dotnet add package Aspire.StackExchange.Redis#:package Aspire.StackExchange.Redis@*<PackageReference Include="Aspire.StackExchange.Redis" Version="*" />Add Garnet client
Section titled “Add Garnet client”In the Program.cs file of your client-consuming project, call the AddRedisClient extension method to register an IConnectionMultiplexer:
builder.AddRedisClient(connectionName: "cache");You can then retrieve the IConnectionMultiplexer instance using dependency injection:
public class ExampleService(IConnectionMultiplexer connectionMux){ // Use connection multiplexer...}Connection properties
Section titled “Connection properties”When you reference a Garnet resource using WithReference, the following connection properties are made available to the consuming project:
Garnet
Section titled “Garnet”The Garnet resource exposes the following connection properties:
| Property Name | Description |
|---|---|
Host | The hostname or IP address of the Garnet server |
Port | The port number the Garnet server is listening on |
Password | The password for authentication (available when a password parameter is configured) |
Uri | The connection URI, with the format redis://:{Password}@{Host}:{Port} |
Example connection string:
Uri: redis://:p%40ssw0rd1@localhost:6379Configuration and other client features
Section titled “Configuration and other client features”Since Garnet is Redis-compatible, all Redis client configuration, keyed services, health checks, and observability features work the same way. See the Redis client integration page for complete client integration documentation.
Distributed caching and output caching
Section titled “Distributed caching and output caching”Garnet also supports Redis distributed caching and output caching. Install the respective packages:
- For distributed caching: 📦 Aspire.StackExchange.Redis.DistributedCaching
- For output caching: 📦 Aspire.StackExchange.Redis.OutputCaching
See Redis Distributed Caching and Redis Output Caching for usage details.