hyp*_*erN 7 c# asp.net-mvc redis stackexchange.redis azure-redis-cache
我已经读过,为了连接到Azure Redis缓存,最好遵循以下做法:
private static ConnectionMultiplexer Connection { get { return LazyConnection.Value; } }
private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
new Lazy<ConnectionMultiplexer>(
() =>
{
return
ConnectionMultiplexer.Connect(connStinrg);
});
Run Code Online (Sandbox Code Playgroud)
根据Azure Redis文档:
Azure Redis缓存的连接由ConnectionMultiplexer类管理.此类旨在在整个客户端应用程序中共享和重用,并且不需要基于每个操作创建.
那么在我的ASP.net MVC应用程序中共享ConnectionMultiplexer的最佳实践是什么?它应该在Global.asax中调用,还是应该每个Controller初始化一次,或者smth.别的?
我也有服务,负责与应用程序通信,所以如果我想在服务内部与Redis通信,我应该将ControlMultiplexer的实例发送到控制器的服务,还是应该在我的所有服务中初始化它,或者?
你可以看到我在这里有点迷失,所以请帮忙!