public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config, int initalDb) { int iConfigedPoolSizeMultiplier; string strMultiplier = ConfigurationManager.AppSettings["RedisPoolSizeMultiplier"]; if (string.IsNullOrEmpty(strMultiplier) == false && int.TryParse(strMultiplier, out iConfigedPoolSizeMultiplier) && iConfigedPoolSizeMultiplier > 0) { this.PoolSizeMultiplier = iConfigedPoolSizeMultiplier; } this.Db = config != null ? config.DefaultDb.GetValueOrDefault(initalDb) : initalDb; ReadWriteHosts = readWriteHosts.ToRedisEndPoints(); ReadOnlyHosts = readOnlyHosts.ToRedisEndPoints(); this.RedisClientFactory = Redis.RedisClientFactory.Instance; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = ReadWriteHosts.Count * PoolSizeMultiplier, MaxReadPoolSize = ReadOnlyHosts.Count * PoolSizeMultiplier, }; if (this.Config.AutoStart) { this.OnStart(); } }
static RedisHelper() { try { RedisClientManagerConfig RedisConfig = new RedisClientManagerConfig(); RedisConfig.AutoStart = true; RedisConfig.MaxReadPoolSize = 60; RedisConfig.MaxWritePoolSize = 60; var hostWrite = System.Configuration.ConfigurationManager.AppSettings["RedisServerWrite"]; var arryWrite = hostWrite.Split(';').ToList(); var hostRead = System.Configuration.ConfigurationManager.AppSettings["RedisServerRead"]; var arryRead = hostWrite.Split(';').ToList(); if (arryWrite.Count > 0 && arryRead.Count > 0) { prcm = new PooledRedisClientManager(arryWrite, arryRead, RedisConfig); redisClient = prcm.GetClient(); } else { throw new Exception("连接服务器失败,请检查配置文件"); } } catch { throw new Exception("连接服务器失败,请检查配置文件"); } }
public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config, long initalDb, int?poolSizeMultiplier, int?poolTimeOutSeconds) { this.Db = config != null ? config.DefaultDb.GetValueOrDefault(initalDb) : initalDb; ReadWriteHosts = readWriteHosts.ToRedisEndPoints(); ReadOnlyHosts = readOnlyHosts.ToRedisEndPoints(); this.RedisClientFactory = Redis.RedisClientFactory.Instance; this.PoolSizeMultiplier = poolSizeMultiplier ?? 10; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = ReadWriteHosts.Count * PoolSizeMultiplier, MaxReadPoolSize = ReadOnlyHosts.Count * PoolSizeMultiplier, }; // if timeout provided, convert into milliseconds this.PoolTimeOut = poolTimeOutSeconds != null ? poolTimeOutSeconds * 1000 : null; if (this.Config.AutoStart) { this.OnStart(); } }
static RedisClientPoolManager() { try { connectTimeout = ConfigUtils.GetSetting("Redis.ConnectTimeout", 1); poolTimeOut = ConfigUtils.GetSetting("Redis.PoolTimeOut", 300); var readWriteHosts = ConfigUtils.GetSetting("Redis.Host.ReadWrite").Split(','); var readOnlyHosts = ConfigUtils.GetSetting("Redis.Host.ReadOnly").Split(','); var password = ConfigUtils.GetConnectionString("Redis.RequirePass"); var dbIndex = ConfigUtils.GetSetting("Redis.Db", 0); dbIndex = dbIndex < 0 ? 0 : dbIndex; readWriteHosts = ConvertHost(readWriteHosts, password); readOnlyHosts = ConvertHost(readOnlyHosts, password); var config = new RedisClientManagerConfig() { //“写”链接池链接数 MaxWritePoolSize = ConfigUtils.GetSetting("Redis.WritePool.MaxSize", 200), //“读”链接池链接数 MaxReadPoolSize = ConfigUtils.GetSetting("Redis.Read.MaxSize", 200), AutoStart = true }; prcm = new PooledRedisClientManager(readWriteHosts, readOnlyHosts, config, dbIndex, PoolSizeMultiplier, poolTimeOut); } catch (Exception ex) { TraceLog.WriteError("Init the redis pool manager error:{0}", ex); } }
/// <summary> /// Hosts can be an IP Address or Hostname in the format: host[:port] /// e.g. 127.0.0.1:6379 /// default is: localhost:6379 /// </summary> /// <param name="readWriteHosts">The write hosts.</param> /// <param name="readOnlyHosts">The read hosts.</param> /// <param name="config">The config.</param> public PooledRedisClientManager( IEnumerable<string> readWriteHosts, IEnumerable<string> readOnlyHosts, RedisClientManagerConfig config) : this(readWriteHosts, readOnlyHosts, config, RedisNativeClient.DefaultDb) { }
/// <summary> /// Hosts can be an IP Address or Hostname in the format: host[:port] /// e.g. 127.0.0.1:6379 /// default is: localhost:6379 /// </summary> /// <param name="readWriteHosts">The write hosts.</param> /// <param name="readOnlyHosts">The read hosts.</param> /// <param name="config">The config.</param> public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config) : this(readWriteHosts, readOnlyHosts, config, RedisNativeClient.DefaultDb) { }
/// <summary> /// Hosts can be an IP Address or Hostname in the format: host[:port] /// e.g. 127.0.0.1:6379 /// default is: localhost:6379 /// </summary> /// <param name="readWriteHosts">The write hosts.</param> /// <param name="readOnlyHosts">The read hosts.</param> /// <param name="config">The config.</param> public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config) : this(readWriteHosts, readOnlyHosts, config, null, null, null) { }
public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config, int initalDb) { this.Db = config != null ? config.DefaultDb.GetValueOrDefault(initalDb) : initalDb; ReadWriteHosts = readWriteHosts.ToIpEndPoints(); ReadOnlyHosts = readOnlyHosts.ToIpEndPoints(); this.RedisClientFactory = Redis.RedisClientFactory.Instance; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = ReadWriteHosts.Count * PoolSizeMultiplier, MaxReadPoolSize = ReadOnlyHosts.Count * PoolSizeMultiplier, }; if (this.Config.AutoStart) { this.OnStart(); } }
/// <summary> /// 建立连接池 /// </summary> public void BuildRedisPoolClient() { RedisClientManagerConfig RedisConfig = new RedisClientManagerConfig(); RedisConfig.AutoStart = true; RedisConfig.MaxReadPoolSize = RedisServicePoolSize; RedisConfig.MaxWritePoolSize = RedisServicePoolSize; PooledRedisClient = new PooledRedisClientManager(RedisServiceAddress, RedisServiceAddress, RedisConfig); }
/// <summary> /// 连接池进行创建连接 /// </summary> /// <returns></returns> public IRedisClient GetClient(List<string> readwritehosts,List<string> readhosts) { RedisClientManagerConfig redisconfig = new RedisClientManagerConfig(); redisconfig.MaxReadPoolSize = 5; redisconfig.MaxWritePoolSize = 5; redisconfig.AutoStart = true; PooledRedisClientManager poolredis = new PooledRedisClientManager(readwritehosts, readhosts, redisconfig); return poolredis.GetClient(); }
public RedisCacheProvider(CacheServerInfo cacheServerInfo) { _cacheServerInfo = cacheServerInfo; var clientManagerConfig = new RedisClientManagerConfig(); clientManagerConfig.MaxWritePoolSize = (int) cacheServerInfo.MaxPoolSize; clientManagerConfig.MaxReadPoolSize = (int) cacheServerInfo.MaxPoolSize; clientManagerConfig.AutoStart = true; var dictionary = new Dictionary<long, PooledRedisClientManager> { {0, new PooledRedisClientManager(cacheServerInfo.ServerHost.Split(','),cacheServerInfo.ServerHost.Split(','), clientManagerConfig)} }; PooledRedisClientManager.Add(cacheServerInfo.CacheType.ToString(), dictionary); }
private RedisManager() { var config = new RedisClientManagerConfig { MaxWritePoolSize = 5, MaxReadPoolSize = 5, AutoStart = true }; _manager = new PooledRedisClientManager( new[] { "deyi@[email protected]:6379" }, new[] { "deyi@[email protected]:6380", "deyi@[email protected]:6381" }, config); // _manager = new PooledRedisClientManager( // new[] { "[email protected]:6379" }, // new[] { "[email protected]:6380", "[email protected]:6381" }, config); }
static ClientRedis() { if (Hosts != null && Hosts.Count > 0 && Clients == null) { var config = new ServiceStack.Redis.RedisClientManagerConfig() { MaxReadPoolSize = PoolSize, MaxWritePoolSize = PoolSize, DefaultDb = Db }; Clients = new List <PooledRedisClientManager>(); foreach (var item in Hosts) { var connect = new string[] { item, item, item }; Clients.Add(new ServiceStack.Redis.PooledRedisClientManager(connect, connect, config)); } } }
private void InitConfig() { var config = ConfigUtils<RedisConfig>.Instance.Get(); if (config == null) { const string msg = "Redis配置文件加载失败!"; _logger.Error(msg); throw new Exception(msg); } var redisConfig = new RedisClientManagerConfig { MaxWritePoolSize = config.WritePoolSize, MaxReadPoolSize = config.ReadPoolSize, AutoStart = config.AutoStart, DefaultDb = config.DefaultDb }; _manager = new PooledRedisClientManager(config.ReadAndWriteServers.Select(t => t.ToString()), config.ReadOnlyServers.Select(t => t.ToString()), redisConfig, 0, 50, 5); _manager.Start(); }
public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config, long?initalDb, int?poolSizeMultiplier, int?poolTimeOutSeconds) { this.Db = config != null ? config.DefaultDb ?? initalDb : initalDb; var masters = (readWriteHosts ?? TypeConstants.EmptyStringArray).ToArray(); var replicas = (readOnlyHosts ?? TypeConstants.EmptyStringArray).ToArray(); RedisResolver = new RedisResolver(masters, replicas); this.PoolSizeMultiplier = poolSizeMultiplier ?? 20; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = RedisConfig.DefaultMaxPoolSize ?? masters.Length * PoolSizeMultiplier, MaxReadPoolSize = RedisConfig.DefaultMaxPoolSize ?? replicas.Length * PoolSizeMultiplier, }; this.OnFailover = new List <Action <IRedisClientsManager> >(); // if timeout provided, convert into milliseconds this.PoolTimeout = poolTimeOutSeconds != null ? poolTimeOutSeconds * 1000 : 2000; //Default Timeout this.AssertAccessOnlyOnSameThread = RedisConfig.AssertAccessOnlyOnSameThread; JsConfig.InitStatics(); if (this.Config.AutoStart) { this.OnStart(); } }
public PooledRedisClientManager( IEnumerable <string> readWriteHosts, IEnumerable <string> readOnlyHosts, RedisClientManagerConfig config, long?initalDb, int?poolSizeMultiplier, int?poolTimeOutSeconds) { this.Db = config != null ? config.DefaultDb ?? initalDb : initalDb; var masters = (readWriteHosts ?? new string[0]).ToArray(); var slaves = (readOnlyHosts ?? new string[0]).ToArray(); RedisResolver = new RedisResolver(masters, slaves); this.PoolSizeMultiplier = poolSizeMultiplier ?? 10; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = masters.Length * PoolSizeMultiplier, MaxReadPoolSize = slaves.Length * PoolSizeMultiplier, }; this.OnFailover = new List <Action <IRedisClientsManager> >(); // if timeout provided, convert into milliseconds this.PoolTimeout = poolTimeOutSeconds != null ? poolTimeOutSeconds * 1000 : 2000; //Default Timeout if (this.Config.AutoStart) { this.OnStart(); } }
/// <summary> /// Redis Configuration /// </summary> public static PooledRedisClientManager GetRedisClientManager(string serverName) { var zone = Math.Max(ExecutionContext<RequestContext>.Current.Zone, 1); var doc = XmlHelper.GetXmlDocCache(EndpointFile); var node = doc != null ? doc.SelectSingleNode("/configuration/redis[@zone='" + zone + "']/server[@name='" + serverName + "']") : null; if (Equals(node, null)) return null; var config = new RedisClientManagerConfig(); var readWriteHosts = new List<string>(); var readOnlyHosts = new List<string>(); foreach (XmlNode item in node.ChildNodes) { switch (item.Name) { case "read": readOnlyHosts.AddRange(from XmlNode rcnode in item.ChildNodes select XmlHelper.GetXmlAttributeValue(rcnode, "uri", string.Empty)); break; case "write": readWriteHosts.AddRange(from XmlNode rcnode in item.ChildNodes select XmlHelper.GetXmlAttributeValue(rcnode, "uri", string.Empty)); break; case "socketPool": config.AutoStart = XmlHelper.GetXmlAttributeValue(item, "autoStart", true); config.MaxReadPoolSize = XmlHelper.GetXmlAttributeValue(item, "maxReadPoolSize", 5); config.MaxWritePoolSize = XmlHelper.GetXmlAttributeValue(item, "maxWritePoolSize", 5); break; } } return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, config); }
public PooledRedisClientManager( IEnumerable<string> readWriteHosts, IEnumerable<string> readOnlyHosts, RedisClientManagerConfig config, int initalDb) { this.Db = config != null ? config.DefaultDb.GetValueOrDefault(initalDb) : initalDb; ReadWriteHosts = readWriteHosts.ToRedisEndPoints(); ReadOnlyHosts = readOnlyHosts.ToRedisEndPoints(); this.RedisClientFactory = Redis.RedisClientFactory.Instance; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = ReadWriteHosts.Count * PoolSizeMultiplier, MaxReadPoolSize = ReadOnlyHosts.Count * PoolSizeMultiplier, }; if (this.Config.AutoStart) { this.OnStart(); } }
public PooledRedisClientManager( IEnumerable<string> readWriteHosts, IEnumerable<string> readOnlyHosts, RedisClientManagerConfig config, int initalDb, int? poolSizeMultiplier, int? poolTimeOutSeconds) { this.Db = config != null ? config.DefaultDb.GetValueOrDefault(initalDb) : initalDb; ReadWriteHosts = readWriteHosts.ToRedisEndPoints(); ReadOnlyHosts = readOnlyHosts.ToRedisEndPoints(); this.RedisClientFactory = Redis.RedisClientFactory.Instance; this.PoolSizeMultiplier = poolSizeMultiplier ?? 10; this.Config = config ?? new RedisClientManagerConfig { MaxWritePoolSize = ReadWriteHosts.Count * PoolSizeMultiplier, MaxReadPoolSize = ReadOnlyHosts.Count * PoolSizeMultiplier, }; // if timeout provided, convert into milliseconds this.PoolTimeOut = poolTimeOutSeconds != null ? poolTimeOutSeconds * 1000 : null; if (this.Config.AutoStart) { this.OnStart(); } }
public void Start(IDictionary<string, string> properties) { // Needs to lock staticly because the pool and the internal maintenance thread // are both static, and I want them syncs between starts and stops. lock (SyncObject) { if (Config == null) { throw new ConfigurationErrorsException("Configuration for NHRedis not found"); } if (_clientManager == null) { var poolConfig = new RedisClientManagerConfig { MaxReadPoolSize = Config.MaxReadPoolSize, MaxWritePoolSize = Config.MaxWritePoolSize }; _clientManager = new PooledRedisClientManager(new List<string>() { Config.Host }, new List<string>(), poolConfig) { RedisClientFactory = new SerializingRedisClientFactory() }; } if (_garbageCollector == null) { // Note: garbage collections disabled because we are using the optimized NHRedis client that // never clears, so no gc needed // _garbageCollector = new RedisGarbageCollector(Config.Host, Config.Port); // _garbageCollector.Start(); } } }