/// <summary> /// redis数据上下文 /// </summary> /// <param name="rule">规则</param> /// <param name="args">参数</param> public RedisContext(IHashAlgorithm hashAlgorithm, RedisCacheOptions options) { _hashAlgorithm = hashAlgorithm; if (!string.IsNullOrWhiteSpace(options.Configuration)) { string[] connectionString = options.Configuration.Split(','); HashSet <string> connSet = new HashSet <string>(); for (int i = 0, j = connectionString.Length; i < j; i++) { var connStr = connectionString[i]; if (connSet.Contains(connStr)) { continue; } connSet.Add(connStr); var hash = new ConsistentHash <ConsistentHashNode>(_hashAlgorithm); var endpoints = connStr.Split(':'); hash.Add(new ConsistentHashNode() { Type = CacheTargetType.Redis, Host = endpoints[0], Port = endpoints[1], UserName = options.InstanceName, Password = options.Pwd, MaxSize = this._maxSize, MinSize = this._minSize, Db = i.ToString() }); dicHash.GetOrAdd(CacheTargetType.Redis.ToString(), hash); } } dicHash = new ConcurrentDictionary <string, ConsistentHash <ConsistentHashNode> >(); }