CacheManger Using Redis Multiplexer with Web.Config Configur



我需要使用两个缓存实例来实现Michael解决方案,就像他在WhatIfRedisStopsWorkingHowDoIkeepMyAppRunning中解释的那样,但在web.config中使用配置。

最后我只有这行代码

var defaultConfig = ConfigurationBuilder.LoadConfiguration("defaultCache");

我找不到如何访问连接多路复用器以将我挂在事件中或通过配置来做到这一点......

可能吗?

有两种方法可以通过 CacheManager 中的 app/web.config 配置 Redis,通过连接字符串

<connectionStrings>
    <add name="redisFromConnectionStrings" connectionString="127.0.0.1:6379,allowAdmin=True,connectTimeout=11,ssl=False,abortConnect=False,connectRetry=10" />
</connectionStrings>

或 Redis 配置部分

<cacheManager.Redis xmlns="http://cachemanager.michaco.net/schemas/RedisCfg.xsd">
<connections>
  <connection id="redisAppConfig" allowAdmin="true" password="" ssl="false" sslHost="" connectionTimeout="11" database="3">
    <endpoints>
      <endpoint host="127.0.0.1" port="6379" />
    </endpoints>
  </connection>
</connections>
</cacheManager.Redis>

:更新:当前没有访问 CacheManager 使用的连接多路复用器的选项。但是,您可以将现有的多路复用器传递给配置。

var defaultConfig = ConfigurationBuilder.LoadConfiguration("defaultCache");
var multiplexer = ConnectionMultiplexer.Connect(...);
defaultConfig = defaultConfig
            .Builder
            .WithRedisConfiguration("redisConfig", multiplexer )
            .Build();

当然,您必须自己实例化多路复用器,并且不能再使用 Web/应用程序配置来配置 Redis 部分。你必须自己处理...

最新更新