instance method get_server_for_key

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

get_server_for_key(key, options = {})

Pick a server to handle the request based on a hash of the key.

Parameters

key req
options opt = {}
Source
# File activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb, line 642
  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

Defined in activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb line 642 · View on GitHub · Improve this page · Find usages on GitHub

Defined in MemCache

Type at least 2 characters to search.

↑↓ navigate · open · esc close