Skip to content

Instantly share code, notes, and snippets.

@mperham
Created Apr 1, 2009
Embed
What would you like to do?
def get_server_for_key(key)
raise ArgumentError, "illegal character in key #{key.inspect}" if key =~ /\s/
raise ArgumentError, "key too long #{key.inspect}" if key.length > 250
raise MemCacheError, "No servers available" if @servers.empty?
# Ignores server weights, oh well
srvs = self.servers.dup
srvs.size.times do |try|
n = rand(srvs.size)
server = srvs[n]
return server if server.alive?
srvs.delete_at(n)
end
raise MemCacheError, "No servers available (all dead)"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment