Skip to content

Improve Redis IDistributedCache integration #8528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sebastienros opened this issue Apr 3, 2025 · 2 comments
Open

Improve Redis IDistributedCache integration #8528

sebastienros opened this issue Apr 3, 2025 · 2 comments
Labels
area-integrations Issues pertaining to Aspire Integrations packages redis Issues related to redis integrations
Milestone

Comments

@sebastienros
Copy link
Member

sebastienros commented Apr 3, 2025

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) => { ... });
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 3, 2025
@eerhardt
Copy link
Member

eerhardt commented Apr 3, 2025

and the prefix "redis3" for its keys

I think the prefix needs to be a separate concern from the service key. Probably the ability to configure the RedisCacheOptions is necessary.

@eerhardt
Copy link
Member

eerhardt commented Apr 3, 2025

I also half wonder if we should make "keyed" distributed caches more of an official support in dotnet/aspnetcore. This isn't criticial to make the experience better in Aspire, but just a thought.

@davidfowl davidfowl added area-integrations Issues pertaining to Aspire Integrations packages redis Issues related to redis integrations and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 4, 2025
@sebastienros sebastienros added this to the Backlog milestone Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages redis Issues related to redis integrations
Projects
None yet
Development

No branches or pull requests

3 participants