Specifying a Redis Connection String with Dot Net Core and Microsoft.Extensions.Caching.StackExchangeRedis

The documentation seems to be a bit sparse when it comes to specifying connection strings with the Microsoft.Extensions.Caching.StackExchangeRedis NuGet package.

If you have any type of non standard configuration then the secret is to pass the connection string in its entirety to options.configuration with additional options separated by a comma. For example, if you wanted to specify a non standard port and use database 1 instead of the default 0 then you could use the following connection string:

services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = "127.0.0.1:6380,DefaultDatabase=1";
});
comments powered by Disqus