Exemplo n.º 1
0
        private static RedisClient CreateRedisClient(RedisPoolSetting setting)
        {
            var client = new RedisClient(setting.Host);

            if (setting.DbIndex > 0)
            {
                client.Db = setting.DbIndex;
            }
            return(client);
        }
Exemplo n.º 2
0
 static RedisConnectionPool()
 {
     _defaultSetting = new RedisPoolSetting
     {
         Host             = ConfigUtils.GetSetting("Redis.Host", "localhost"),
         MaxWritePoolSize = ConfigUtils.GetSetting("Redis.MaxWritePoolSize", 100),
         MaxReadPoolSize  = ConfigUtils.GetSetting("Redis.MaxReadPoolSize", 100),
         ConnectTimeout   = ConfigUtils.GetSetting("Redis.ConnectTimeout", 0),
         PoolTimeOut      = ConfigUtils.GetSetting("Redis.PoolTimeOut", 0),
         DbIndex          = ConfigUtils.GetSetting("Redis.Db", 0)
     };
     _defaultSetting.ReadOnlyHost = ConfigUtils.GetSetting("Redis.ReadHost", _defaultSetting.Host);
 }
Exemplo n.º 3
0
        private static RedisClient CreateRedisClient(RedisPoolSetting setting)
        {
            string[]    hostParts;
            RedisClient client = null;

            if (setting.Host.Contains("@"))
            {
                hostParts = setting.Host.Split('@', ':');
                client    = new RedisClient(hostParts[1], hostParts[2].ToInt(), hostParts[0], setting.DbIndex);
            }
            else
            {
                hostParts = setting.Host.Split(':');
                int port = hostParts.Length > 1 ? hostParts[1].ToInt() : 6379;
                client = new RedisClient(hostParts[0], port, null, setting.DbIndex);
            }
            return(client);
        }
Exemplo n.º 4
0
        /// <summary>
        /// init
        /// </summary>
        /// <param name="setting">pool setting</param>
        public static void Initialize(RedisPoolSetting setting)
        {
            string[] readWriteHosts = setting.Host.Split(',');
            string[] readOnlyHosts  = setting.ReadOnlyHost.Split(',');
            var      redisConfig    = new RedisClientManagerConfig
            {
                MaxWritePoolSize = setting.MaxWritePoolSize,
                MaxReadPoolSize  = setting.MaxReadPoolSize,
                DefaultDb        = setting.DbIndex,
                AutoStart        = false
            };

            _pooledRedis = new PooledRedisClientManager(readWriteHosts, readOnlyHosts, redisConfig);
            if (setting.ConnectTimeout > 0)
            {
                _pooledRedis.ConnectTimeout = setting.ConnectTimeout;
            }
            if (setting.PoolTimeOut > 0)
            {
                _pooledRedis.PoolTimeout = setting.PoolTimeOut;
            }
            _pooledRedis.Start();
        }
Exemplo n.º 5
0
 /// <summary>
 /// init
 /// </summary>
 /// <param name="setting">pool setting</param>
 /// <param name="serializer"></param>
 public static void Initialize(RedisPoolSetting setting, ICacheSerializer serializer)
 {
     _setting    = setting;
     _serializer = serializer;
     //string[] readWriteHosts = setting.Host.Split(',');
     //string[] readOnlyHosts = setting.ReadOnlyHost.Split(',');
     //var redisConfig = new RedisClientManagerConfig
     //{
     //    MaxWritePoolSize = setting.MaxWritePoolSize,
     //    MaxReadPoolSize = setting.MaxReadPoolSize,
     //    DefaultDb = setting.DbIndex,
     //    AutoStart = false
     //};
     //_pooledRedis = new PooledRedisClientManager(readWriteHosts, readOnlyHosts, redisConfig);
     //if (setting.ConnectTimeout > 0)
     //{
     //    _pooledRedis.ConnectTimeout = setting.ConnectTimeout;
     //}
     //if (setting.PoolTimeOut > 0)
     //{
     //    _pooledRedis.PoolTimeout = setting.PoolTimeOut;
     //}
     //_pooledRedis.Start();
 }
Exemplo n.º 6
0
 /// <summary>
 /// init
 /// </summary>
 /// <param name="setting">pool setting</param>
 /// <param name="serializer"></param>
 public static void Initialize(RedisPoolSetting setting, ICacheSerializer serializer)
 {
     _setting    = setting;
     _serializer = serializer;
     InitRedisInfo();
 }