コード例 #1
0
 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>();
 }
コード例 #2
0
ファイル: Startup.cs プロジェクト: egbertn/BlogFeederService
        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;
            });
        }