Skip to content

Commit

Permalink
Ensure that ping test clients are always disconnected after use. Don'…
Browse files Browse the repository at this point in the history
…t assume that a good slave was found.
  • Loading branch information
cheald committed Mar 1, 2016
1 parent 8dd7deb commit 7ec1aa3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/redis/client.rb
Expand Up @@ -584,15 +584,18 @@ def resolve_nearest_slave
:port => slave["port"],
:reconnect_attempts => 0
)
client.call [:ping]
start = Time.now
client.call [:ping]
slave["response_time"] = (Time.now - start).to_f
client.disconnect
begin
client.call [:ping]
start = Time.now
client.call [:ping]
slave["response_time"] = (Time.now - start).to_f
ensure
client.disconnect
end
end

slave = ok_slaves.sort_by {|slave| slave["response_time"] }.first
{:host => slave.fetch("ip"), :port => slave.fetch("port")}
{:host => slave.fetch("ip"), :port => slave.fetch("port")} if slave
end
end
end
Expand Down

0 comments on commit 7ec1aa3

Please sign in to comment.