Beispiel #1
0
 public RedisCache(RedisSetting setting)
 {
     _db = RedisManager.GetClient(setting);
     _localCacheEnable  = setting.LocalCacheEnable;
     _localCacheTimeout = setting.LocalCacheTimeout;
     if (_localCacheTimeout == 0)
     {
         _localCacheTimeout = 60;
     }
 }
Beispiel #2
0
        public static IDatabase GetClient(RedisSetting setting)
        {
            var config     = _settings.GetOrAdd(setting.ClientName, item => setting);
            var connection = _connnections.AddOrUpdate(setting.ClientName, key =>
            {
                return(ConnectionMultiplexer.Connect(Convert(config), _log));
            },
                                                       (key, old) =>
            {
                if (!old.IsConnected)
                {
                    old.Close();
                    old.Dispose();
                    old = ConnectionMultiplexer.Connect(Convert(config), _log);
                }
                return(old);
            });

            return(connection.GetDatabase());
        }
Beispiel #3
0
        private static ConfigurationOptions Convert(RedisSetting setting)
        {
            string[] writeServerList = setting.ServerList.Split(',');
            var      sdkOptions      = new ConfigurationOptions
            {
                ClientName         = setting.ClientName,
                KeepAlive          = 5 * 60,
                DefaultVersion     = new Version(setting.Version),
                AbortOnConnectFail = false,
                DefaultDatabase    = setting.DefaultDb,
                ConnectRetry       = 10,
                Password           = setting.Password,
            };

            foreach (var s in writeServerList)
            {
                sdkOptions.EndPoints.Add(s);
            }
            ;
            return(sdkOptions);
        }