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.
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_hash ⇒ Object (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 |
#names ⇒ Object (readonly)
Returns the value of attribute names.
4 5 6 |
# File 'lib/solid_cache/connections/sharded.rb', line 4 def names @names end |
#nodes ⇒ Object (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 |
#count ⇒ Object
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 |