/// <summary>
 ///     redis 连接
 /// </summary>
 /// <param name="sectionName"></param>
 /// <param name="dbIndex"></param>
 public SERedisConnection(string sectionName, int dbIndex)
 {
     _sectionName = sectionName;
     _dbIndex     = dbIndex;
     Pool         = SERedisConnectionPoolManager.GetPool(_sectionName);
     _cnn         = Pool.GetConnection();
 }
Exemple #2
0
        /// <summary>
        ///     初始化池,类似于构造方法
        ///     不要重复调用
        /// </summary>
        /// <param name="redisConfig"></param>
        public void Init(RedisConfig redisConfig)
        {
            if (redisConfig == null)
            {
                throw new Exception("传入的redisConfig实例不能空");
            }
            _sectionName     = redisConfig.SectionName;
            _BusyRetry       = redisConfig.BusyRetry;
            _BusyRetryWaitMS = redisConfig.BusyRetryWaitMS;
            if (string.IsNullOrWhiteSpace(_sectionName))
            {
                throw new Exception("redisConfig.SectionName不能为空");
            }

            lock (locker)
            {
                if (SERedisConnectionPoolManager.Exists(_sectionName))
                {
                    return;
                }

                var configStr = GenerateConnectionString(redisConfig);

                if ((redisConfig.PoolSize < 1) || (redisConfig.PoolSize > 100))
                {
                    redisConfig.PoolSize = 1;
                }

                //哨兵特殊处理
                if (redisConfig.Type == 1)
                {
                    var sentinel = new SESentinelClient(_sectionName, configStr, redisConfig.PoolSize, redisConfig.Password);

                    sentinel.OnRedisServerChanged += sentinel_OnRedisServerChanged;

                    var operateRedisConnecitonString = sentinel.Start();

                    _SentinelPool.AddOrUpdate(_sectionName + "_" + redisConfig.ServiceName, sentinel, (x, y) => sentinel);

                    SERedisConnectionPoolManager.Create(_sectionName, operateRedisConnecitonString, redisConfig.PoolSize);
                }
                else
                {
                    SERedisConnectionPoolManager.Create(_sectionName, configStr, redisConfig.PoolSize);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// 哨兵监测事件
 /// </summary>
 /// <param name="section"></param>
 /// <param name="newConnectionString"></param>
 /// <param name="poolSize"></param>
 private void sentinel_OnRedisServerChanged(string section, string newConnectionString, int poolSize)
 {
     SERedisConnectionPoolManager.Update(_InstanceName, newConnectionString, poolSize);
 }