/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.CSRedis.DefaultCSRedisCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="clients">Clients.</param> /// <param name="serializer">Serializer.</param> /// <param name="options">Options.</param> /// <param name="loggerFactory">Logger factory.</param> public DefaultCSRedisCachingProvider( string name, IEnumerable <EasyCachingCSRedisClient> clients, IEasyCachingSerializer serializer, IOptionsMonitor <RedisOptions> options, ILoggerFactory loggerFactory = null) { this._name = name; this._serializer = serializer; this._options = options.CurrentValue; this._logger = loggerFactory?.CreateLogger <DefaultCSRedisCachingProvider>(); this._cache = clients.FirstOrDefault(x => x.Name.Equals(_name)); this._cacheStats = new CacheStats(); }
/// <summary> /// Uses the CSRedis. /// </summary> /// <returns>The CSR edis.</returns> /// <param name="options">Options.</param> /// <param name="configuration">Configuration.</param> /// <param name="name">Name.</param> /// <param name="sectionName">Section name.</param> public static EasyCachingOptions UseCSRedis(this EasyCachingOptions options, IConfiguration configuration, string name = EasyCachingConstValue.DefaultCSRedisName, string sectionName = EasyCachingConstValue.CSRedisSection) { var dbConfig = configuration.GetSection(sectionName); var redisOptions = new RedisOptions(); dbConfig.Bind(redisOptions); void configure(RedisOptions x) { x.EnableLogging = redisOptions.EnableLogging; x.MaxRdSecond = redisOptions.MaxRdSecond; x.DBConfig = redisOptions.DBConfig; } options.RegisterExtension(new RedisOptionsExtension(name, configure)); return(options); }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.CSRedis.DefaultCSRedisCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="clients">Clients.</param> /// <param name="serializers">Serializers.</param> /// <param name="options">Options.</param> /// <param name="loggerFactory">Logger factory.</param> public DefaultCSRedisCachingProvider( string name, IEnumerable <EasyCachingCSRedisClient> clients, IEnumerable <IEasyCachingSerializer> serializers, RedisOptions options, ILoggerFactory loggerFactory = null) { this._name = name; this._serializer = serializers.FirstOrDefault(x => x.Name.Equals(_name)) ?? serializers.Single(x => x.Name.Equals(EasyCachingConstValue.DefaultSerializerName)); this._options = options; this._logger = loggerFactory?.CreateLogger <DefaultCSRedisCachingProvider>(); this._cache = clients.Single(x => x.Name.Equals(_name)); this._cacheStats = new CacheStats(); this.ProviderName = this._name; this.ProviderType = CachingProviderType.Redis; this.ProviderStats = this._cacheStats; this.ProviderMaxRdSecond = _options.MaxRdSecond; this.IsDistributedProvider = true; }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.CSRedis.DefaultCSRedisCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="clients">Clients.</param> /// <param name="serializer">Serializer.</param> /// <param name="options">Options.</param> /// <param name="loggerFactory">Logger factory.</param> public DefaultCSRedisCachingProvider( string name, IEnumerable <EasyCachingCSRedisClient> clients, IEasyCachingSerializer serializer, IOptionsMonitor <RedisOptions> options, ILoggerFactory loggerFactory = null) { this._name = name; this._serializer = serializer; this._options = options.CurrentValue; this._logger = loggerFactory?.CreateLogger <DefaultCSRedisCachingProvider>(); this._cache = clients.FirstOrDefault(x => x.Name.Equals(_name)); this._cacheStats = new CacheStats(); this.ProviderName = this._name; this.ProviderStats = this._cacheStats; this.ProviderType = _options.CachingProviderType; this.ProviderOrder = _options.Order; this.ProviderMaxRdSecond = _options.MaxRdSecond; this.IsDistributedProvider = true; }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.CSRedis.DefaultCSRedisCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="clients">Clients.</param> /// <param name="serializers">Serializers.</param> /// <param name="options">Options.</param> /// <param name="factory">Distributed lock factory</param> /// <param name="loggerFactory">Logger factory.</param> public DefaultCSRedisCachingProvider( string name, IEnumerable <EasyCachingCSRedisClient> clients, IEnumerable <IEasyCachingSerializer> serializers, RedisOptions options, CSRedisLockFactory factory = null, ILoggerFactory loggerFactory = null) : base(factory, options) { this._name = name; this._options = options; this._logger = loggerFactory?.CreateLogger <DefaultCSRedisCachingProvider>(); this._cache = clients.Single(x => x.Name.Equals(_name)); this._cacheStats = new CacheStats(); this._serializer = !string.IsNullOrWhiteSpace(options.SerializerName) ? serializers.Single(x => x.Name.Equals(options.SerializerName)) : serializers.FirstOrDefault(x => x.Name.Equals(_name)) ?? serializers.Single(x => x.Name.Equals(EasyCachingConstValue.DefaultSerializerName)); this.ProviderName = this._name; this.ProviderType = CachingProviderType.Redis; this.ProviderStats = this._cacheStats; this.ProviderMaxRdSecond = _options.MaxRdSecond; this.IsDistributedProvider = true; _info = new ProviderInfo { CacheStats = _cacheStats, EnableLogging = options.EnableLogging, IsDistributedProvider = IsDistributedProvider, LockMs = options.LockMs, MaxRdSecond = options.MaxRdSecond, ProviderName = ProviderName, ProviderType = ProviderType, SerializerName = options.SerializerName, SleepMs = options.SleepMs, Serializer = _serializer, CacheNulls = options.CacheNulls, }; }