public void Close() { foreach (var item in this.nodes) { ClusterNode node = item.Value; if (node.IsConnected()) { RedisNativeClient client = null; if (this.clients.TryGetValue(Network.IPv4ToUlong(node.ip, node.port), out client)) { client.Quit(); } } node.Clear(); } this.nodes.Clear(); this.clients.Clear(); this.disconnected.Clear(); for (var i = 0; i < Global.HashSlotSize; ++i) { this.slots[i] = null; } }
public void Update() { // Get a connected Redis client. ClusterNode node = null; RedisNativeClient client = null; foreach (var item in this.nodes) { node = item.Value; if (node.IsConnected()) { client = this.GetRedisClient(node.ip, node.port); if (this.disconnected.Contains(client)) { // TODO: The quit operation seems unnecessary. client.Quit(); this.disconnected.Remove(client); this.clients.Remove(Network.IPv4ToUlong(node.ip, node.port)); // This Redis client has to reconnect to the Redis cluster. client = this.GetRedisClient(node.ip, node.port); } // Return a connected Redis client. break; } } if (client == null) { // TODO: All clients are disconnected. return; } // Update information on this Redis cluster. this.Update(client, node.ip); }