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) ⇒ 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) ⇒ 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_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
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 |
#count ⇒ Object
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 |