Skip to content

Commit

Permalink
Cache connections in get_random_connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Feb 19, 2013
1 parent 0ed7dc4 commit 95c126a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cluster.rb
Expand Up @@ -88,8 +88,15 @@ def get_random_connection
e = ""
@startup_nodes.each{|n|
begin
n[:name] = "#{n[:host]}:#{n[:port]}" if not n[:name]
return @connections[n[:name]] if @connections[n[:name]]
r = Redis.new(:host => n[:host], :port => n[:port])
return r if r.ping == "PONG"
if r.ping == "PONG"
@connections[n[:name]] = r
return r
else
# TODO: close 'r' ASAP when it will be possible.
end
rescue => e
# Just try with the next node.
end
Expand Down

0 comments on commit 95c126a

Please sign in to comment.