Exemplo n.º 1
0
        /// <summary>
        /// 获取RedisClient
        /// </summary>
        /// <param name="redisUri"></param>
        /// <returns></returns>
        private static IRedisClient CreateClietManage(string redisUri)
        {
            if (string.IsNullOrWhiteSpace(redisUri))
            {
                return(null);
            }

            var list = StringHelper.ToArray(redisUri);

            if (list == null || (list != null && list.Count == 0))
            {
                return(null);
            }

            try
            {
                var reads            = list.FirstOrDefault(x => String.Equals(x.Key, "Reads", StringComparison.CurrentCultureIgnoreCase)).Value.Split(',');
                var writes           = list.FirstOrDefault(x => String.Equals(x.Key, "Writes", StringComparison.CurrentCultureIgnoreCase)).Value.Split(',');
                var maxWritePoolSize = IntHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "MaxWritePoolSize", StringComparison.CurrentCultureIgnoreCase)).Value);
                var maxReadPoolSize  = IntHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "MaxReadPoolSize", StringComparison.CurrentCultureIgnoreCase)).Value);
                var autoStart        = BoolHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "AutoStart", StringComparison.CurrentCultureIgnoreCase)).Value);

                PooledRedisClientManager manage = new PooledRedisClientManager(reads, writes, new RedisClientManagerConfig
                {
                    MaxWritePoolSize = maxWritePoolSize,
                    MaxReadPoolSize  = maxReadPoolSize,
                    AutoStart        = autoStart,
                });
                return(manage.GetClient());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private static PooledRedisClientManager CreateManage(string redisUri)
        {
            if (VerifyHelper.IsEmpty(redisUri))
            {
                throw new Exception("RedisUri is Null");
            }


            var list = StringHelper.ToKeyValueList(redisUri);

            if (VerifyHelper.IsEmpty(list))
            {
                throw new Exception("RedisUri is Null");
            }

            try
            {
                var reads            = list.FirstOrDefault(x => String.Equals(x.Key, "Reads", StringComparison.CurrentCultureIgnoreCase)).Value.Split(',');
                var writes           = list.FirstOrDefault(x => String.Equals(x.Key, "Writes", StringComparison.CurrentCultureIgnoreCase)).Value.Split(',');
                var maxWritePoolSize = IntHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "MaxWritePoolSize", StringComparison.CurrentCultureIgnoreCase)).Value);
                var maxReadPoolSize  = IntHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "MaxReadPoolSize", StringComparison.CurrentCultureIgnoreCase)).Value);
                var autoStart        = BoolHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "AutoStart", StringComparison.CurrentCultureIgnoreCase)).Value);

                PooledRedisClientManager manage = new PooledRedisClientManager(reads, writes, new RedisClientManagerConfig
                {
                    MaxWritePoolSize = maxWritePoolSize,
                    MaxReadPoolSize  = maxReadPoolSize,
                    AutoStart        = autoStart,
                });
                return(manage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }