diff --git a/lib/redis/client.rb b/lib/redis/client.rb index af2f2326d..695ca71bb 100755 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -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