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) ⇒ Sharded

Returns a new instance of Sharded.



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

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

Instance Attribute Details

#consistent_hashObject (readonly)

Returns the value of attribute consistent_hash.



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

def consistent_hash
  @consistent_hash
end

#namesObject (readonly)

Returns the value of attribute names.



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

def names
  @names
end

#nodesObject (readonly)

Returns the value of attribute nodes.



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

def nodes
  @nodes
end

Instance Method Details

#assign(keys) ⇒ Object



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

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

#countObject



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

def count
  names.count
end

#with(name, &block) ⇒ Object



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

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

#with_connection_for(key, &block) ⇒ Object



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

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

#with_each(&block) ⇒ Object



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

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

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