Catch Microsoft.Extensions.Caching.Redis connection fail?

Viewed 1377

I need to use Microsoft.Extensions.Caching.Redis into my asp.net core project.

I put this code into ConfigureService (Startup.cs):

IDistributedCache cache = new RedisCache(new RedisCacheOptions
{
    Configuration = Configuration.GetConnectionString("Redis"),
    InstanceName = "Master"
});

services.AddSingleton<IDistributedCache>(cache);

What I need is to catch a connection exception (in case the Redis server is down, or the server is not reachable), but I haven't found a method to check connection and if I wrap code into a try/catch nothing happens.

Is there a way to accomplish my task?

Thanks

1 Answers
Related