示例#1
0
        /// <summary>
        /// 构建哨兵高可用redis服务
        /// </summary>
        /// <param name="master">主库</param>
        /// <param name="sentinels">哨兵</param>
        /// <param name="isSlave">是否读写分离</param>
        public void BuildSentinel(bool isSlave, RedisModel master, params RedisModel[] sentinels)
        {
            try
            {
                List <string> _conns = new List <string>();

                foreach (var _sentinel in sentinels)
                {
                    _conns.Add(_sentinel.ToString());
                }

                _cli             = new RedisClient(master.ToString(), _conns.ToArray(), isSlave);
                _cli.Serialize   = obj => JsonSerializer.Serialize(obj);
                _cli.Deserialize = (json, type) => JsonSerializer.Deserialize(json, type);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        /// <summary>
        /// 构建标准读写分离池redis服务
        /// </summary>
        /// <param name="write"></param>
        /// <param name="reads"></param>
        public void BuildPooling(RedisModel write, RedisModel[] reads)
        {
            try
            {
                List <ConnectionStringBuilder> _conns = new List <ConnectionStringBuilder>();

                foreach (var _read in reads)
                {
                    _conns.Add(_read.ToString());
                }

                _cli             = new RedisClient(write.ToString(), _conns.ToArray());
                _cli.Serialize   = obj => JsonSerializer.Serialize(obj);
                _cli.Deserialize = (json, type) => JsonSerializer.Deserialize(json, type);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }