Skip to content

Instantly share code, notes, and snippets.

@GeradeDev
Created March 4, 2020 11:51
Show Gist options
  • Save GeradeDev/4456dc81f5d772803847949a0ebbb0ff to your computer and use it in GitHub Desktop.
Save GeradeDev/4456dc81f5d772803847949a0ebbb0ff to your computer and use it in GitHub Desktop.
public static IServiceCollection AddRedis(this IServiceCollection services, IConfiguration configuration)
{
var redisCacheSettings = new RedisOptions();
configuration.GetSection(SectionName).Bind(redisCacheSettings);
services.AddSingleton(redisCacheSettings);
if (!redisCacheSettings.Enabled)
{
return services;
}
services.AddSingleton<IConnectionMultiplexer>(_ => ConnectionMultiplexer.Connect(redisCacheSettings.ConnectionString));
services.AddStackExchangeRedisCache(options => options.Configuration = redisCacheSettings.ConnectionString);
services.AddSingleton<IResponseCacheService, ResponseCacheService>();
return services;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment