Class: SolidCache::Connections::Sharded

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_cache/connections/sharded.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names, nodes) ⇒ Sharded

Returns a new instance of Sharded.



6
7
8
9
10
# File 'lib/solid_cache/connections/sharded.rb', line 6

def initialize(names, nodes)
  @names = names
  @nodes = nodes
  @consistent_hash = MaglevHash.new(@nodes.keys)
end

Instance Attribute Details

#consistent_hashObject (readonly)

Returns the value of attribute consistent_hash.



4
5
6
# File 'lib/solid_cache/connections/sharded.rb', line 4

def consistent_hash
  @consistent_hash
end

#namesObject (readonly)

Returns the value of attribute names.



4
5
6
# File 'lib/solid_cache/connections/sharded.rb', line 4

def names
  @names
end

#nodesObject (readonly)

Returns the value of attribute nodes.



4
5
6
# File 'lib/solid_cache/connections/sharded.rb', line 4

def nodes
  @nodes
end

Instance Method Details

#assign(keys) ⇒ Object



26
27
28
# File 'lib/solid_cache/connections/sharded.rb', line 26

def assign(keys)
  keys.group_by { |key| shard_for(key.is_a?(Hash) ? key[:key] : key) }
end

#countObject



30
31
32
# File 'lib/solid_cache/connections/sharded.rb', line 30

def count
  names.count
end

#with(name, &block) ⇒ Object



18
19
20
# File 'lib/solid_cache/connections/sharded.rb', line 18

def with(name, &block)
  Record.with_shard(name, &block)
end

#with_connection_for(key, &block) ⇒ Object



22
23
24
# File 'lib/solid_cache/connections/sharded.rb', line 22

def with_connection_for(key, &block)
  with(shard_for(key), &block)
end

#with_each(&block) ⇒ Object



12
13
14
15
16
# File 'lib/solid_cache/connections/sharded.rb', line 12

def with_each(&block)
  return enum_for(:with_each) unless block_given?

  names.each { |name| with(name, &block) }
end