Skip to content
Docs Try Aspire
Docs Try

Get started with Redis distributed caching

Redis logo

The Redis® distributed caching integration is the IDistributedCache flavor of the Redis client integration for ASP.NET Core. It uses the same Redis hosting integration (Aspire.Hosting.Redis) to model the Redis container in your AppHost, but the consuming-app side is provided by Aspire.StackExchange.Redis.DistributedCaching — a C#-only library that registers an IDistributedCache implementation backed by Redis. TypeScript, Go, and Python consumers should use the regular Redis client integration directly.

Why use Redis distributed caching with Aspire

Section titled “Why use Redis distributed caching with Aspire”

Adding the Redis distributed caching integration through Aspire — rather than wiring up connection strings and service registrations by hand — gives you:

  • Drop-in IDistributedCache implementation. One line registers a fully functional IDistributedCache backed by Redis, compatible with session state, data protection, and [OutputCache].
  • Automatic service registration. AddRedisDistributedCache handles IDistributedCache, the underlying IConnectionMultiplexer, and all required plumbing in a single call.
  • Built-in health checks. The integration registers a health check that verifies the Redis instance is reachable before your app reports healthy.
  • OpenTelemetry out of the box. Logging, distributed tracing, and metrics are wired up automatically through the standard Aspire telemetry pipeline.
  • Works with ASP.NET Core higher-level abstractions. Because IDistributedCache is the standard ASP.NET Core caching abstraction, this integration works transparently with output caching, session state, and ASP.NET Core Data Protection.

The Redis distributed caching integration has two sides: the hosting integration in your AppHost that models the Redis resource, and the C# client integration in consuming apps that registers IDistributedCache.

architecture-beta

  group apphost(server)[AppHost]
  group consumer(server)[Consuming app]

  service hosting(server)[Hosting integration] in apphost
  service redis(server)[Redis server] in apphost

  service client(iconoir:server-connection)[StackExchange Redis distributed cache client] in consumer
  service app(server)[App] in consumer

  hosting:R --> L:redis
  redis:R --> L:client
  client:R --> L:app

The hosting integration lives in your AppHost project and models the Redis server as a resource. The client integration lives in each consuming C# app and uses the connection information Aspire injects to register IDistributedCache.

Getting there is a two-step process: model the Redis resource in your AppHost, then register IDistributedCache in your consuming app.

  1. Add the Redis hosting integration to your AppHost, declare a Redis resource, and reference it from the apps that need distributed caching. The Redis distributed caching AppHost article covers the installation and the basic AddRedis call. For the full AppHost API surface — data volumes, persistence, Redis Insight, Redis Commander, parameters, and more — see the Redis Hosting integration reference.

    Set up Redis distributed caching in the AppHost

  2. Once the Redis resource is referenced from your consuming project, Aspire injects the connection information. See Connect to Redis distributed caching for the connection properties reference, how to call AddRedisDistributedCache, keyed clients, configuration options, health checks, telemetry, and usage examples.

    Connect to Redis distributed caching