dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.23k stars 9.95k forks source link

Access the singleton ConnectionMultiplexer or have a new IDatabase while also using IDistributedCache interface #28374

Open bragma opened 4 years ago

bragma commented 4 years ago

Is your feature request related to a problem? Please describe.

I'm trying to use our Redis server from an ASP .NET Core Web Api via the IDistributedCache interface. While this is OK, I'd also like to be able to use other data types/access modes from Redis via direct commands, i.e. I'd like to be able to use the IDatabase private member directly, preserving the IDistributedCache interface.

Describe the solution you'd like

Some way to be able to use the same IDatabase _cached property directly or at least created a new one from a public Connect() method using the existing ConnectionMultiplexer object.

Describe alternatives you've considered

In setup.cs, creating a singleton object RedisCache and keep a reference to it, also passing it as a service singleton instance. This may cause problems with the Connect() lock, though.

Thanks!

analogrelay commented 4 years ago

We won't expose the ConnectionMultiplexer in DI. We don't put types we don't control into the DI container because it can mess with a lot of different DI services.

What we could do instead is offer a Func<ConnectionMutiplexer> "factory" option on the RedisCacheOptions. Then you could specify your own connection and share it with other components.

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

JunTaoLuo commented 3 years ago

Related: https://github.com/dotnet/aspnetcore/issues/28379