/// <inheritdoc /> public virtual RedisClient CreateRedisClient(RedisEndpoint config, bool master) { var client = this.ClientFactory(config); if (!master || !RedisConfig.VerifyMasterConnections) { return(client); } var role = client.GetServerRole(); if (role == RedisServerRole.Master) { return(client); } Interlocked.Increment(ref RedisState.TotalInvalidMasters); _logger.Error(string.Format("Redis Master Host '{0}' is {1}. Resetting allHosts...", config.GetHostString(), role)); var newMasters = new List <RedisEndpoint>(); var newSlaves = new List <RedisEndpoint>(); RedisClient masterClient = null; foreach (var hostConfig in this._allHosts) { try { var testClient = this.ClientFactory(hostConfig); testClient.ConnectTimeout = RedisConfig.HostLookupTimeoutMs; var testRole = testClient.GetServerRole(); switch (testRole) { case RedisServerRole.Master: newMasters.Add(hostConfig); if (masterClient == null) { masterClient = testClient; } break; case RedisServerRole.Slave: newSlaves.Add(hostConfig); break; } } catch { /* skip */ } } if (masterClient == null) { Interlocked.Increment(ref RedisState.TotalNoMastersFound); var errorMsg = "No master found in: " + string.Join(", ", this._allHosts.Select(x => x.GetHostString())); _logger.Error(errorMsg); throw new Exception(errorMsg); } this.ResetMasters(newMasters); this.ResetSlaves(newSlaves); return(masterClient); }