/// <summary> /// 根据字库类别查询RedisConfig.xml获取各字库的信息 /// </summary> /// <param name="catelog"></param> /// <returns></returns> private static RedisModel GetRedisModel(string catelog) { RedisModel r = null; string path = AppDomain.CurrentDomain.BaseDirectory + "/" + RedisConfigName; if (!File.Exists(path)) { return(null); } XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode xn = doc.SelectSingleNode("root"); XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xnr in xnl) { XmlElement xe = (XmlElement)xnr; if (xe.GetAttribute("catelog") == catelog) { r = new RedisModel(); r.Ip = xe.GetAttribute("ip"); r.Port = int.Parse(xe.GetAttribute("port")); r.Pwd = xe.GetAttribute("pwd"); r.Db = long.Parse(xe.GetAttribute("db")); break; } } if (r == null) { LogHelper.Error("RedisConfig.xml文件中未找到catelog:" + catelog); } return(r); }
/// <summary> /// 单实例方式,单例方式需要指定db /// </summary> /// <param name="catelog"></param> /// <returns></returns> private IRedisClient GetRedisClientBySingle(string catelog) { IRedisClient result; bool b = RedisCatelogDictionary.TryGetValue(catelog, out result); if (!b) { RedisModel rm = GetRedisModel(catelog); result = new RedisClient(rm.Ip, rm.Port, rm.Pwd, rm.Db); RedisCatelogDictionary.TryAdd(catelog, result); } return(result); }
/// <summary> /// 初始化Pool /// </summary> /// <param name="catelog"></param> /// <returns></returns> private PooledRedisClientManager InitPool(string catelog) { int _RedisPoolSize = 10000; int _RedisPoolTimeoutSeconds = 2; RedisModel _rm = GetRedisModel(catelog); if (_rm == null) { return(null); } PooledRedisClientManager Instance = new PooledRedisClientManager(_RedisPoolSize, _RedisPoolTimeoutSeconds, new string[] { string.Format("{0}@{1}:{2}", _rm.Pwd, _rm.Ip, _rm.Port) }) { ConnectTimeout = 10000 // 1500 }; PoolInstanceDictonary.TryAdd(catelog, Instance); return(Instance); }