Skip to content

Instantly share code, notes, and snippets.

Created Apr 1, 2009
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?
raise MemCacheError, "No servers available (all dead)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment