Class: FastCache::ModulusBucket

Inherits:
Object
  • Object
show all
Defined in:
lib/fastcache/bucket/modulus.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodes) ⇒ ModulusBucket

Returns a new instance of ModulusBucket.



3
4
5
# File 'lib/fastcache/bucket/modulus.rb', line 3

def initialize(nodes)
  @nodes = nodes
end

Instance Method Details

#select(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fastcache/bucket/modulus.rb', line 7

def select(hash)
  count = @nodes.size
  count.times do |i|
    begin
      break yield(@nodes[(hash + i) % count])
    rescue FastCache::Memcache::ProtocolError
      next
    end
    raise 'Unable to find suitable node to communicate with'
  end
end