我的问题很简单,但我想知道如何对Microsoft分布式Redis缓存使用singeleton DI?当我检查我们的startup.cs时。我意识到出了点问题。你对此有什么看法?
services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect(Configuration.GetConnectionString(ProjectConst.Config.AzureRedisCacheConnection)));
var redisConnString = Configuration.GetConnectionString(ProjectConst.Config.AzureRedisCacheConnection);
services.AddDistributedRedisCache(options =>
{
options.Configuration = redisConnString;
options.InstanceName = "Test";
});
我认为下面的代码足以满足分布式cach的需求。我猜想“ AddDistributedRedisCache”对缓存不是必需的。
services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect(Configuration.GetConnectionString(ProjectConst.Config.AzureRedisCacheConnection)));
这足以分发吗?感谢您的回答。