class FastCache::ModulusBucket def initialize(key, hash) @digest = hash.new(key).hexdigest.to_i(16) @key = key end def select(nodes) count = nodes.size # Note: An upper bound on tries ought to be given at some point count.times do |i| begin break yield(@key, nodes[(@digest + i) % count]) rescue FastCache::Memcache::ProtocolError next end raise 'Unable to find suitable node to communicate with' end end end