question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RedisCache] Allow injection of ConnectionMultiplexer

See original GitHub issue

Currently 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:closed
  • Created 6 years ago
  • Reactions:17
  • Comments:72 (39 by maintainers)

github_iconTop GitHub Comments

4reactions
davidfowlcommented, Aug 22, 2017

Yes we should allow for this. Not sure about injecting the IConnectionMultiplexer as a dependency though we should have an option that allows setting a Func<IConnectionMultiplexer>

3reactions
analogrelaycommented, Sep 30, 2019

I think that’s why there’s ConnectionMultiplexer.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redis-Dependency Injection of the ConnectionMultiplexer
Configure Redis using Dependency Injection of the ConnectionMultiplexer Redis; Redis Connection for Replica set; Starting RedisServer; Redis – IDistributedCache ...
Read more >
Should `StackExchange.Redis.ConnectionMultiplexer` be ` ...
This then means I can use IConnectionMultiplexer for the dependency injection anywhere. My question is: ConnectionMultiplexer is designed to be ...
Read more >
Dependency Injected StackExchange.Redis Client
ConfigurationOptions allows us to initialize service with more Redis servers(Redis ... ConnectionMultiplexer redis = ConnectionMultiplexer.
Read more >
Dependency Injection | Jeremy Lindsay
Posts about Dependency Injection written by Jeremy Lindsay. ... Category: Dependency Injection ... Redis.ConnectionMultiplexer.Connect(Configuration.
Read more >
How Do I Use Redis In .Net Core
Let's start with installation;. You can follow these steps from the official page of Redis depending on your operating system.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found