Should `StackExchange.Redis.ConnectionMultiplexer` be `AddStatic` or `AddScope` in .NET Core dependency injection?

ε祈祈猫儿з 提交于 2019-12-05 06:04:39

What is the load expected to the app ? If you have much concurrency, I think using AddScoped would mean a lot of unnecessary burden to initiate and close connections for every request.

Also these observations IMHO show that you should use AddSingleton

(...) it is exceptionally rare that you would want to use a ConnectionMultiplexer briefly, as the idea is to re-use this object.

Another common use of redis is as a pub/sub message distribution tool; this is also simple, and in the event of connection failure, the ConnectionMultiplexer will handle all the details of re-subscribing to the requested channels.

Also, you will save memory having only one instance of ConnectionMultiplexer (IMHO).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!