# File lib/memcache.rb, line 208 def get_server_for_key(key) # Easy enough if there is only one server. return @servers.first if @servers.length == 1 # Hash the value of the key to select the bucket. hkey = key.hash # Fetch a server for the given key, retrying if that server is # offline. server = nil 20.times do |tries| server = @buckets[(hkey + tries) % @buckets.nitems] break if server.alive? end raise MemCacheError, "No servers available" unless server server end