thepirat000 / CachingFramework.Redis

Distributed caching based on StackExchange.Redis and Redis. Includes support for tagging and is cluster-compatible.
Other
287 stars 52 forks source link

Question on long lived RedisContext documentation #55

Closed CDargis closed 5 years ago

CDargis commented 5 years ago

Hi there. Not an issue just a question. The documentation here reads

The RedisContext object should be shared and reused between callers. It is not recommended to create a RedisContext per operation. Please check StackExchange.Redis documentation for more information.

Is it the RedisContext object that must be long-lived or the IConnectionMultiplexer ? Meaning if my multiplexer is long-lived and I am newing up RedisContext objects and injecting in the multiplexer, there is no concern there? Asking because I'll be using CachingFramework.Redis alongside another (separate) framework that requires a StackExchange.Redis.IConnectionMultiplexer. I'd like both frameworks to use the same pool of multiplexers.

Thanks.

thepirat000 commented 5 years ago

It is the IConnectionMultiplexer which should be long-lived. The RedisContext object holds a reference to the connection multiplexer. So I think you are doing fine, as long as the multiplexer you are injecting is long-lived.

Another option would be to maintain just a static RedisContext object and when you need the IConnectionMultiplexer you can get it with var mux = redisContext.GetConnectionMultiplexer()

CDargis commented 5 years ago

Thanks!