1

I need to implement Michael solution using two Cache Instances like he explain in WhatIfRedisStopsWorkingHowDoIkeepMyAppRunning but using configuration in web.config.

Finally i only have this line of code

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

I don`t find how to access to the ConnectionMultiplexer to hook me in the events or do it by config...

Is posible?

Gerardo Seró
  • 33
  • 1
  • 5

1 Answers1

2

There are two ways to configure Redis via app/web.config in CacheManager, via ConnectionString

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

or Redis configuration section

<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>

:UPDATE: There is currently no option to access the connection multiplexer used by CacheManager. But you can pass in an existing multiplexer to the configuration.

var defaultConfig = ConfigurationBuilder.LoadConfiguration("defaultCache");
var multiplexer = ConnectionMultiplexer.Connect(...);

defaultConfig = defaultConfig
            .Builder
            .WithRedisConfiguration("redisConfig", multiplexer )
            .Build();

Of course you have to instantiate the multiplexer yourself and cannot use the web/app config anymore to configure the Redis part. You'd have to handle that yourself...

MichaC
  • 13,104
  • 2
  • 44
  • 56
  • That's not what i mean. I already have CacheManager and Redis configured in web.config. What i need is add a IConnectionMultiplexer to catch the events of the connection configured with web.config. – Gerardo Seró Jun 13 '17 at 13:31
  • @GerardoSeró Ah got it, sorry, you'd have to instantiate the connection multiplexer yourself then and pass that into the configuration part for redis. see update – MichaC Jun 13 '17 at 14:45
  • Just before your answer I ended up using configuration by code. Thx – Gerardo Seró Jun 14 '17 at 13:16