Skip to content

Improve Redis IDistributedCache integration #8528

Open
@sebastienros

Description

@sebastienros

The current implementation doesn't support multiple IDistributedCache instances to be registered, either using dedicated Redis instances or a shared one with prefixes.

This is due to how the IDistributedCache is used in aspnetcore and also how the extension method to register the service is designed. This is confusing users as reported here and from internal usage.

dotnet/docs-aspire#2625

The suggestion is to change the current API to support these scenarios.

The following usage would then be possible:

builder.AddRedisDistributedCache("redis1");
builder.AddKeyedRedisDistributedCache(name: "redis2");
builder.AddKeyedRedisDistributedCache(name: "redis2", serviceKey: "redis3");

This would result in:

  • a non-keyed IDistributedCache service registration using the Redis resource redis1
  • a keyed IDistributedCache service using a different Redis resource redis2, and no key prefix
  • a keyed IDistributedCache service using the same Redis resource redis2, but with the "redis3" service key, and the prefix "redis3" for its keys

Service resolution would be done like so:

app.MapGet("/cache1", async (IDistributedCache cache) => { ... });
app.MapGet("/cache2", async ([FromKeyedServices("redis2")] IDistributedCache cache) => { ... });
app.MapGet("/cache3", async ([FromKeyedServices("redis3")] IDistributedCache cache) => { ... });

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-integrationsIssues pertaining to Aspire Integrations packagesredisIssues related to redis integrations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions