public SerializerService(IConnectionMultiplexer cache, IOptions <DistributedCacheConfig> config, ILogger <SerializerService> logger) { _config = config == null ? new DistributedCacheConfig { DataTimeOut = 60 } : config.Value; _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _logger = logger ?? new NullLogger <SerializerService>(); }
private void ConfigureRedisCache(IServiceCollection services) { var distributedCacheConfig = new DistributedCacheConfig(); Configuration.GetSection("RedisOptions").Bind(distributedCacheConfig); if (distributedCacheConfig.UseInMemory) { // services.AddDistributedMemoryCache(); return; } services.AddStackExchangeRedisCache(opt => { var password = distributedCacheConfig.Password; if (password == "nil" || password == "") { password = null; } if (string.IsNullOrEmpty(password) && distributedCacheConfig.Ssl) { throw new Exception("Missing distributedcache password in configuration."); } var options = new ConfigurationOptions { Ssl = distributedCacheConfig.Ssl, ConnectRetry = distributedCacheConfig.ConnectRetry, SslProtocols = System.Security.Authentication.SslProtocols.None, ConnectTimeout = distributedCacheConfig.ConnectTimeout, DefaultDatabase = distributedCacheConfig.DefaultDatabase, Password = password, AbortOnConnectFail = true, EndPoints = { { distributedCacheConfig.Endpoint, distributedCacheConfig.EndpointPort } } }; opt.ConfigurationOptions = options; }); }