[RedisCache] Allow injection of ConnectionMultiplexer
See original GitHub issueCurrently the RedisCache
creates the ConnectionMultiplexer
and does not allow access to it. This prevents the application from reusing the ConnectionMultiplexer
for other operations like PubSub.
Granted, the application could create another ConnectionMultiplexer
, but the recommendation is to have only one per application.
I was thinking if it would be possible to have a separate constructor for RedisCache
that would receive the ConnectionMultiplexer
. I understand that so far Microsoft.Extensions.Caching.Redis did not leak any implementation details about its usage of StackExchange.Redis. However, I noticed that Microsoft.AspNetCore.DataProtection.Redis leaks StackExchange.Redis types here. So, I’m unclear about how you feel about keeping StackExchange.Redis as an implementation detail.
Proposed API
namespace Microsoft.Extensions.Caching.StackExchangeRedis
{
public class RedisCacheOptions
{
+ Func<IConnectionMultiplexer> ConnectionMultiplexerFactory { get; set; }
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:17
- Comments:72 (39 by maintainers)
Yes we should allow for this. Not sure about injecting the
IConnectionMultiplexer
as a dependency though we should have an option that allows setting aFunc<IConnectionMultiplexer>
Yep, I understand the purpose. Just trying to understand what issues you’re seeing with using two separate instances to help prioritize. Is there extra load in your system? (memory usage, cpu, etc.)
We’ll definitely be investigating this, but I just want to understand how this issue is negatively impacting applications right now in order to help us prioritize.