Пример #1
0
        /// <summary>
        /// Init
        /// </summary>
        public void Init()
        {
            RedisConfigurationSection redis = ConfigurationManager.GetSection("redis") as RedisConfigurationSection;

            _tKeepAlive.Interval = redis.KeepAliveInterval;
            string[] arrR = redis.ReadOnlyHosts.Split(',').Select(x => x.Trim()).ToArray();
            foreach (var item in arrR)
            {
                var info = HostInfoTool.Parse(item);
                _lsRedisClients.Add(new RedisClient(info.Ip, info.Port, info.Pwd));

                _lsStatusInfos.Add(new StatusInfo
                {
                    Addr     = string.Format("{0}:{1}", info.Ip, info.Port),
                    IsOnline = true
                });
            }

            _tKeepAlive.Start();
        }
        /// <summary>
        /// Init
        /// </summary>
        public static void Init()
        {
            JsConfig.DateHandler    = DateHandler.ISO8601DateTime;
            JsConfig.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

            RedisConfigurationSection redisSection = ConfigurationManager.GetSection("redis") as RedisConfigurationSection;

            IsKeepAliveMode = redisSection.IsKeepAlive;
            IsSentinelMode  = redisSection.IsSentinel;

            if (IsKeepAliveMode)
            {
                KeepAliveService.Instance.Init();
            }

            if (!IsSentinelMode)
            {
                string[] arrRW = redisSection.ReadWriteHosts.Split(',').Select(x => x.Trim()).ToArray();
                string[] arrR  = redisSection.ReadOnlyHosts.Split(',').Select(x => x.Trim()).ToArray();

                Prcm = new PooledRedisClientManager(arrRW, arrR, new RedisClientManagerConfig
                {
                    MaxWritePoolSize = redisSection.MaxWritePoolSize,
                    MaxReadPoolSize  = redisSection.MaxReadPoolSize,
                    AutoStart        = redisSection.AutoStart
                });
            }
            else
            {
                SentinelNodePwd = redisSection.SentinelNodePwd;

                var           ls = redisSection.SentinelHosts.Split(',').Select(x => x.Trim()).ToList();
                RedisSentinel rs = new RedisSentinel(ls);
                Rcm = rs.Start();
            }
        }