Class: SolidCache::Connections::Sharded
- Inherits:
-
Object
- Object
- SolidCache::Connections::Sharded
- Defined in:
- lib/solid_cache/connections/sharded.rb
Instance Attribute Summary collapse
-
#consistent_hash ⇒ Object
readonly
Returns the value of attribute consistent_hash.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #assign(keys) ⇒ Object
- #count ⇒ Object
-
#initialize(names, nodes) ⇒ Sharded
constructor
A new instance of Sharded.
- #with(name, &block) ⇒ Object
- #with_connection_for(key, &block) ⇒ Object
- #with_each(&block) ⇒ Object
Constructor Details
#initialize(names, nodes) ⇒ Sharded
Returns a new instance of Sharded.
8 9 10 11 12 |
# File 'lib/solid_cache/connections/sharded.rb', line 8 def initialize(names, nodes) @names = names @nodes = nodes @consistent_hash = MaglevHash.new(@nodes.keys) end |
Instance Attribute Details
#consistent_hash ⇒ Object (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 |
#names ⇒ Object (readonly)
Returns the value of attribute names.
6 7 8 |
# File 'lib/solid_cache/connections/sharded.rb', line 6 def names @names end |
#nodes ⇒ Object (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
28 29 30 |
# File 'lib/solid_cache/connections/sharded.rb', line 28 def assign(keys) keys.group_by { |key| shard_for(key.is_a?(Hash) ? key[:key] : key) } end |
#count ⇒ Object
32 33 34 |
# File 'lib/solid_cache/connections/sharded.rb', line 32 def count names.count end |
#with(name, &block) ⇒ Object
20 21 22 |
# File 'lib/solid_cache/connections/sharded.rb', line 20 def with(name, &block) Record.with_shard(name, &block) end |
#with_connection_for(key, &block) ⇒ Object
24 25 26 |
# File 'lib/solid_cache/connections/sharded.rb', line 24 def with_connection_for(key, &block) with(shard_for(key), &block) end |
#with_each(&block) ⇒ Object
14 15 16 17 18 |
# File 'lib/solid_cache/connections/sharded.rb', line 14 def with_each(&block) return enum_for(:with_each) unless block_given? names.each { |name| with(name, &block) } end |