Created
November 5, 2009 19:20
-
-
Save jdunphy/227307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Pick a server to handle the request based on a hash of the key. | |
def get_server_for_key(key, options = {}) | |
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? | |
return @servers.first if @servers.length == 1 | |
hkey = hash_for(key) | |
20.times do |try| | |
entryidx = Continuum.binary_search(@continuum, hkey) | |
server = @continuum[entryidx].server | |
return server if server.alive? | |
break unless failover | |
hkey = hash_for "#{try}#{key}" | |
end | |
raise MemCacheError, "No servers available" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment