class RedisClient::SentinelConfig

def each_sentinel

def each_sentinel
  last_error = nil
  @sentinel_configs.dup.each do |sentinel_config|
    sentinel_client = sentinel_client(sentinel_config)
    success = true
    begin
      yield sentinel_client
    rescue RedisClient::Error => error
      last_error = error
      success = false
      sleep SENTINEL_DELAY
    ensure
      if success
        @sentinel_configs.unshift(@sentinel_configs.delete(sentinel_config))
      end
      # Redis Sentinels may be configured to have a lower maxclients setting than
      # the Redis nodes. Close the connection to the Sentinel node to avoid using
      # a connection.
      sentinel_client.close
    end
  end
  raise last_error if last_error
end