internal CacheClientTestBase(ISerializer serializer)
        {
            redisConfiguration = new RedisConfiguration()
            {
                AbortOnConnectFail = true,
                KeyPrefix          = "MyPrefix__",
                Hosts = new RedisHost[]
                {
                    new RedisHost {
                        Host = "localhost", Port = 6379
                    }
                },
                AllowAdmin                = true,
                ConnectTimeout            = 3000,
                Database                  = 0,
                PoolSize                  = 5,
                ServerEnumerationStrategy = new ServerEnumerationStrategy()
                {
                    Mode       = ServerEnumerationStrategy.ModeOptions.All,
                    TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
                    UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw
                }
            };

            var moqLogger = new Mock <ILogger <RedisCacheConnectionPoolManager> >();

            this.serializer       = serializer;
            connectionPoolManager = new RedisCacheConnectionPoolManager(redisConfiguration, moqLogger.Object);
            sut = new RedisCacheClient(connectionPoolManager, this.serializer, redisConfiguration);
            db  = sut.GetDbFromConfiguration().Database;
        }
Beispiel #2
0
        public static IRedisDatabase Instance(IConfiguration config, ISerializer sz = null)
        {
            if (config == null)
            {
                throw new ArgumentException("Redis:Configuration is not Exists");
            }
            var app = config.GetSection("App").Get <string>();

            if (string.IsNullOrEmpty(app))
            {
                throw new ArgumentException("Redis:APP is not Exists");
            }
            var apptype     = (App)Enum.Parse(typeof(App), app);
            var key         = String.Format("Reis{0}", app);
            var redisConfig = config.GetSection(key).Get <RedisConfiguration>();

            if (redisConfig == null)
            {
                throw new ArgumentException("Redis:redisConfig is not Exists");
            }
            if (!CacheClientArry.ContainsKey(apptype))
            {
                var cacheClient = GetCacheClient(redisConfig, sz);
                if (cacheClient != null)
                {
                    CacheClientArry.TryAdd(apptype, cacheClient);
                }
            }
            IRedisCacheClient client = CacheClientArry[apptype];
            var db = client.GetDb((int)apptype);

            return(db);
        }
Beispiel #3
0
        /// <summary>
        /// 默认缓存服务
        /// </summary>
        /// <param name="optionsAccessor">设置访问器</param>
        /// <param name="distributedCache">分布式缓存器</param>
        /// <param name="localCache">本地内存缓存器</param>
        /// <param name="logger">日志</param>
        public DefaultCacheService(IOptions <CacheServiceOptions> optionsAccessor,
                                   IRedisCacheClient distributedCache,
                                   IMemoryCache localCache,
                                   ILogger <DefaultCacheService> logger)
        {
            if (optionsAccessor == null)
            {
                throw new ArgumentNullException(nameof(optionsAccessor));
            }
            this.logger  = logger;
            this.options = optionsAccessor.Value;
            if (options.EnableDistributedCache && distributedCache != null)
            {
                this.cache = new DistributedMemoryCache(distributedCache);
            }
            else
            {
                this.cache = new RuntimeMemoryCache(localCache);
            }
            this.localCache                  = new RuntimeMemoryCache(localCache);
            this.EnableDistributedCache      = options.EnableDistributedCache;
            this.cachingExpirationDictionary = new Dictionary <CachingExpirationType, TimeSpan>();
            this.cachingExpirationDictionary.Add(CachingExpirationType.Invariable, new TimeSpan(0, 0, (int)(86400f * options.CacheExpirationFactor)));
            this.cachingExpirationDictionary.Add(CachingExpirationType.Stable, new TimeSpan(0, 0, (int)(28800f * options.CacheExpirationFactor)));
            this.cachingExpirationDictionary.Add(CachingExpirationType.RelativelyStable, new TimeSpan(0, 0, (int)(7200f * options.CacheExpirationFactor)));
            this.cachingExpirationDictionary.Add(CachingExpirationType.UsualSingleObject, new TimeSpan(0, 0, (int)(600f * options.CacheExpirationFactor)));
            this.cachingExpirationDictionary.Add(CachingExpirationType.UsualObjectCollection, new TimeSpan(0, 0, (int)(300f * options.CacheExpirationFactor)));
            this.cachingExpirationDictionary.Add(CachingExpirationType.SingleObject, new TimeSpan(0, 0, (int)(180f * options.CacheExpirationFactor)));
            this.cachingExpirationDictionary.Add(CachingExpirationType.ObjectCollection, new TimeSpan(0, 0, (int)(180f * options.CacheExpirationFactor)));

            this.logger.LogInformation($"DefaultCacheService::Init,EnableDistributedCache:{options.EnableDistributedCache},CacheExpirationFactor:{options.CacheExpirationFactor}.");
        }
Beispiel #4
0
 public DBMaintenanceController(ILogger <DBMaintenanceController> logger, DEMODBContext context, IRedisCacheClient cacheClient, IPinCacheKeyGenerator keyGen)
 {
     _logger      = logger;
     _context     = context;
     _cacheClient = cacheClient;
     _keyGen      = keyGen;
 }
Beispiel #5
0
 public RedisChacheDownstreamService(ILogger <MemCacheDownStreamService> logger, IConfiguration configuration, HttpClient httpClient, IRedisCacheClient cache) : base(logger, httpClient)
 {
     _config     = configuration;
     _logger     = logger;
     _httpClient = httpClient;
     _cache      = cache;
 }
 public UpdateCartService(IRedisCacheClient redisCacheClient, ILogger <UpdateCartService> logger, IConfiguration configuration, IGetCartItems getCartItems)
 {
     _redisCacheClient = redisCacheClient;
     _logger           = logger;
     _config           = configuration;
     _getCartItems     = getCartItems;
 }
Beispiel #7
0
 public PinRepository(ILogger <IPinRepository> logger, IRedisCacheClient redisClient, IPinCacheKeyGenerator cacheKeyGenerator, DEMODBContext dbContext)
 {
     _logger            = logger;
     _redisClient       = redisClient;
     _cacheKeyGenerator = cacheKeyGenerator;
     _dbContext         = dbContext;
 }
Beispiel #8
0
        private static async Task NewMethod(IRedisCacheClient _redisClient)
        {
            await GenerateClocks(_redisClient.Db1);

            await LookupSingleItem(_redisClient.Db1);
            await LookupAllItems(_redisClient.Db1);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="redisCacheClient"></param>
 public PlaceRepository(
     IConfiguration configuration,
     ILoggerFactory loggerFactory,
     IRedisCacheClient redisCacheClient
     ) : base(configuration, loggerFactory.CreateLogger <Repository.RedisRepository.PlaceRepository>(), redisCacheClient)
 {
 }
Beispiel #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="localizer"></param>
 /// <param name="configuration"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="redisCacheClient"></param>
 /// <param name="emailSender"></param>
 /// <param name="smsSender"></param>
 /// <param name="placeRepository"></param>
 /// <param name="slotRepository"></param>
 /// <param name="placeProviderRepository"></param>
 /// <param name="userRepository"></param>
 public VisitorRepository(
     IStringLocalizer <Repository.RedisRepository.VisitorRepository> localizer,
     IConfiguration configuration,
     ILoggerFactory loggerFactory,
     IRedisCacheClient redisCacheClient,
     IEmailSender emailSender,
     ISMSSender smsSender,
     IPlaceRepository placeRepository,
     ISlotRepository slotRepository,
     IPlaceProviderRepository placeProviderRepository,
     IUserRepository userRepository
     ) : base(
         localizer,
         configuration,
         loggerFactory.CreateLogger <Repository.RedisRepository.VisitorRepository>(),
         redisCacheClient,
         emailSender,
         smsSender,
         placeRepository,
         slotRepository,
         placeProviderRepository,
         userRepository
         )
 {
     logger             = loggerFactory.CreateLogger <VisitorRepository>();
     this.configuration = configuration;
 }
 public GameService(IOptions <GameSettings> settings, ILogger <GameService> logger, IRedisCacheClient redisCacheClient, IOptions <CosmosSettings> cosmosSettings, IHttpContextAccessor httpContextAccessor)
 {
     _settings            = settings.Value;
     _logger              = logger;
     _redisCacheClient    = redisCacheClient;
     _cosmosSettings      = cosmosSettings.Value;
     _httpContextAccessor = httpContextAccessor;
 }
Beispiel #12
0
 public RedisClient(LoggingClient _logger, IRedisCacheClient _redis, int _cacheLife, CacheType _cacheType, string _key)
 {
     redis     = _redis;
     cacheLife = _cacheLife;
     key       = _key;
     logger    = _logger;
     cacheType = _cacheType;
 }
Beispiel #13
0
        public WeatherForecastController(
            IRedisCacheClient redis
            )
        {
            _redis = redis;

            Init();
        }
Beispiel #14
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="logger"></param>
        /// <param name="redisCacheClient"></param>

        public PlaceRepository(
            IConfiguration configuration,
            ILogger <PlaceRepository> logger,
            IRedisCacheClient redisCacheClient
            )
        {
            this.logger           = logger;
            this.redisCacheClient = redisCacheClient;
            this.configuration    = configuration;
        }
Beispiel #15
0
        private const int DEFAULT_LOCK_TTL = 300000; // 300 seconds.


        /// <summary>
        ///     A general purpose ID locking system that utilizes Redis as its backend storage medium.  This is just an in memory store
        ///     that can be used to determine if some object (based upon its type (name) and unique identifier) are being used elsewhere
        ///     in the system and thus cannot be accessed.
        /// </summary>
        /// <param name="redisCacheClient">Reference to a RedisCacheClient that can be used to communicate with the Redis infrastructure </param>
        /// <param name="redisDatabaseNumber">The number of the database that should be used to store locks in.  It is recommended, but not required
        /// that locks be stored in a database all to their own.  The reason, is if all locks need to be flushed it can be much faster to flush the
        /// entire Database than to work thru all the lock types.</param>
        /// <param name="isDedicatedLockDatabase">Set to True, if the database to be used for storing locks is dedicated to this use only or if it
        /// is shared with other uses (caching values, etc).  There is a slight performance boost if using dedicated. </param>
        public RedisLocker(IRedisCacheClient redisCacheClient, byte redisDatabaseNumber = 0, bool isDedicatedLockDatabase = false)
        {
            _redisDB = redisCacheClient.GetDb(redisDatabaseNumber);
            _isDedicatedLockDatabase = isDedicatedLockDatabase;

            // Clear the Lock Prefix if this is a dedicated database - no need for it, since everything in the database is a lock entry.
            if (isDedicatedLockDatabase)
            {
                LockPrefix = "";
            }
        }
Beispiel #16
0
 public CacheConfigManager(
     IHostEnvironment env,
     IConfigManager innerManager,
     IRedisCacheClient cacheClient,
     ILogger <CacheConfigManager> logger = null)
 {
     this._env           = env ?? throw new ArgumentNullException(nameof(env));
     this._configManager = innerManager ?? throw new ArgumentNullException(nameof(innerManager));
     this._cacheClient   = cacheClient ?? throw new ArgumentNullException(nameof(cacheClient));
     this._logger        = logger;
 }
Beispiel #17
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="localizer"></param>
 /// <param name="configuration"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="redisCacheClient"></param>
 public SlotRepository(
     IStringLocalizer <Repository.RedisRepository.SlotRepository> localizer,
     IConfiguration configuration,
     ILoggerFactory loggerFactory,
     IRedisCacheClient redisCacheClient
     ) : base(localizer,
              configuration,
              loggerFactory.CreateLogger <Repository.RedisRepository.SlotRepository>(),
              redisCacheClient
              )
 {
 }
Beispiel #18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="localizer"></param>
 /// <param name="configuration"></param>
 /// <param name="logger"></param>
 /// <param name="redisCacheClient"></param>
 public SlotRepository(
     IStringLocalizer <SlotRepository> localizer,
     IConfiguration configuration,
     ILogger <SlotRepository> logger,
     IRedisCacheClient redisCacheClient
     )
 {
     this.localizer        = localizer;
     this.logger           = logger;
     this.configuration    = configuration;
     this.redisCacheClient = redisCacheClient;
 }
Beispiel #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="logger"></param>
 /// <param name="redisCacheClient"></param>
 /// <param name="placeRepository"></param>
 public PlaceProviderRepository(
     IConfiguration configuration,
     ILogger <PlaceProviderRepository> logger,
     IRedisCacheClient redisCacheClient,
     IPlaceRepository placeRepository
     )
 {
     this.logger           = logger;
     this.redisCacheClient = redisCacheClient;
     this.configuration    = configuration;
     this.placeRepository  = placeRepository;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="redisCacheClient"></param>
 /// <param name="placeRepository"></param>
 public PlaceProviderRepository(
     IConfiguration configuration,
     ILoggerFactory loggerFactory,
     IRedisCacheClient redisCacheClient,
     IPlaceRepository placeRepository
     ) : base(
         configuration,
         loggerFactory.CreateLogger <Repository.RedisRepository.PlaceProviderRepository>(),
         redisCacheClient,
         placeRepository)
 {
     this.configuration = configuration;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IRedisCacheClient cacheClient)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            cacheClient.Db0.Add("key", "int");
            var result = cacheClient.Db0.Get <string>("key");

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
Beispiel #22
0
        public async Task RedisSetWebAsync(string key, IRedisCacheClient _cacheClient, RedisWeb obj)
        {
            await _cacheClient.Db0.AddAsync(key, obj);

            if (Webkeys.Count >= REDIS_MAX)
            {
                IDictionary <string, RedisWeb> dictionary = await _cacheClient.Db0.GetAllAsync <RedisWeb>(Webkeys);

                ICollection <RedisWeb> collection = dictionary.Values;

                ClickHouseInsertWeb(EnumerableWebConverter(collection));
                await _cacheClient.Db0.RemoveAllAsync(Webkeys);

                Webkeys.Clear();
            }
        }
Beispiel #23
0
        public async Task RedisSetMobileAsync(string key, IRedisCacheClient _cacheClient, RedisMobile obj)
        {
            await _cacheClient.Db0.AddAsync(key, obj);

            if (Mobilekeys.Count >= REDIS_MAX)
            {
                IDictionary <string, RedisMobile> dictionary = await _cacheClient.Db0.GetAllAsync <RedisMobile>(Mobilekeys);

                ICollection <RedisMobile> collection = dictionary.Values;

                ClickHouseInsertMobile(EnumerableMobileConverter(collection));
                await _cacheClient.Db0.RemoveAllAsync(Mobilekeys);

                Mobilekeys.Clear();
            }
        }
        public PiosService(IOptions <PiosServiceOptions> options, ILogger <PiosService> logger, IRedisCacheClient redis)
        {
            // Initialize the options.
            _options = options.Value;

            // Initialize injected stuff.
            _logger = logger;
            _redis  = redis;

            // Save the cache TTL.
            _cache_ttl = _options.CacheTtl;

            // Determine the scheme to be used.
            var scheme = _options.Secure ? "https" : "http";

            // Initialize the builder.
            _builder = new UriBuilder(scheme, _options.Host, _options.Port, _options.Path);
        }
        public void Setup()
        {
            ServiceProvider = new ServiceCollection()
                              .AddStackExchangeRedisExtensions <NewtonsoftSerializer>(new RedisConfiguration
            {
                Password       = "******",
                AllowAdmin     = true,
                Ssl            = false,
                ConnectTimeout = 6000,
                Database       = 0,
                Hosts          = new[] { new RedisHost {
                                             Host = "##.##.##.##", Port = 6379
                                         } }
            })
                              .BuildServiceProvider();

            _redisCacheClient = ServiceProvider.GetService <IRedisCacheClient>();
        }
Beispiel #26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="localizer"></param>
 /// <param name="configuration"></param>
 /// <param name="logger"></param>
 /// <param name="redisCacheClient"></param>
 /// <param name="emailSender"></param>
 /// <param name="smsSender"></param>
 /// <param name="placeRepository"></param>
 /// <param name="placeProviderRepository"></param>
 public UserRepository(
     IStringLocalizer <UserRepository> localizer,
     IConfiguration configuration,
     ILogger <UserRepository> logger,
     IRedisCacheClient redisCacheClient,
     IEmailSender emailSender,
     ISMSSender smsSender,
     IPlaceRepository placeRepository,
     IPlaceProviderRepository placeProviderRepository
     )
 {
     this.localizer               = localizer;
     this.logger                  = logger;
     this.redisCacheClient        = redisCacheClient;
     this.emailSender             = emailSender;
     this.smsSender               = smsSender;
     this.configuration           = configuration;
     this.placeRepository         = placeRepository;
     this.placeProviderRepository = placeProviderRepository;
 }
Beispiel #27
0
        public override Task OnActivateAsync()
        {
            Identity      = this.GetPrimaryKeyLong();
            _Logger       = ServiceProvider.GetService <ILoggerFactory>().CreateLogger("Node[" + Identity + "]");
            _CacheClient  = ServiceProvider.GetService <IRedisCacheClient>();
            _IMongoClient = ServiceProvider.GetService <IMongoClient>();

            EntityManager = new EntityManager();
            SyncManager   = new EventManager <SyncType>();
            TimerManager  = new TimerManager(this);

            BatchCahceList = new List <NList>();

            SyncManager.Register(SyncType.Entity, OnSyncEntity);
            SyncManager.Register(SyncType.Field, OnSyncField);
            SyncManager.Register(SyncType.Table, OnSyncTable);

            RegisterTimer(BatchCache, null, TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(TimeUtils.MINITE));

            return(base.OnActivateAsync());
        }
Beispiel #28
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="localizer"></param>
 /// <param name="localizer2"></param>
 /// <param name="configuration"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="redisCacheClient"></param>
 /// <param name="emailSender"></param>
 /// <param name="smsSender"></param>
 /// <param name="placeRepository"></param>
 /// <param name="placeProviderRepository"></param>
 public UserRepository(
     IStringLocalizer <UserRepository> localizer,
     IStringLocalizer <Repository.RedisRepository.UserRepository> localizer2,
     IConfiguration configuration,
     ILoggerFactory loggerFactory,
     IRedisCacheClient redisCacheClient,
     IEmailSender emailSender,
     ISMSSender smsSender,
     IPlaceRepository placeRepository,
     IPlaceProviderRepository placeProviderRepository
     ) : base(
         localizer2,
         configuration,
         loggerFactory.CreateLogger <Repository.RedisRepository.UserRepository>(),
         redisCacheClient,
         emailSender,
         smsSender,
         placeRepository,
         placeProviderRepository
         )
 {
     this.localizer = localizer;
     this.placeProviderRepository = placeProviderRepository;
 }
 public UserController(IRedisCacheClient redisCacheClient)
 {
     _redisCacheClient = redisCacheClient;
 }
 public RedisService(IRedisCacheClient _cacheClient, ISerializer _serializer)
 {
     cacheClient = _cacheClient;
     serializer  = _serializer;
 }