Module: SolidCache::Cluster::Connections
- Included in:
- SolidCache::Cluster
- Defined in:
- lib/solid_cache/cluster/connections.rb
Instance Attribute Summary collapse
-
#shard_options ⇒ Object
readonly
Returns the value of attribute shard_options.
Instance Method Summary collapse
- #connection_names ⇒ Object
- #connections ⇒ Object
- #group_by_connection(keys) ⇒ Object
- #initialize(options = {}) ⇒ Object
- #with_connection(name, async: false, &block) ⇒ Object
- #with_connection_for(key, async: false, &block) ⇒ Object
- #with_each_connection(async: false, &block) ⇒ Object
Instance Attribute Details
#shard_options ⇒ Object (readonly)
Returns the value of attribute shard_options.
6 7 8 |
# File 'lib/solid_cache/cluster/connections.rb', line 6 def @shard_options end |
Instance Method Details
#connection_names ⇒ Object
41 42 43 |
# File 'lib/solid_cache/cluster/connections.rb', line 41 def connection_names connections.names end |
#connections ⇒ Object
45 46 47 |
# File 'lib/solid_cache/cluster/connections.rb', line 45 def connections @connections ||= SolidCache::Connections.from_config(@shard_options) end |
#group_by_connection(keys) ⇒ Object
37 38 39 |
# File 'lib/solid_cache/cluster/connections.rb', line 37 def group_by_connection(keys) connections.assign(keys) end |
#initialize(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/solid_cache/cluster/connections.rb', line 8 def initialize( = {}) super() @shard_options = .fetch(:shards, nil) if [ Hash, Array, NilClass ].none? { |klass| @shard_options.is_a? klass } raise ArgumentError, "`shards` is a `#{@shard_options.class.name}`, it should be one of Array, Hash or nil" end end |
#with_connection(name, async: false, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/solid_cache/cluster/connections.rb', line 31 def with_connection(name, async: false, &block) connections.with(name) do execute(async, &block) end end |
#with_connection_for(key, async: false, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/solid_cache/cluster/connections.rb', line 25 def with_connection_for(key, async: false, &block) connections.with_connection_for(key) do execute(async, &block) end end |
#with_each_connection(async: false, &block) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/solid_cache/cluster/connections.rb', line 17 def with_each_connection(async: false, &block) return enum_for(:with_each_connection) unless block_given? connections.with_each do execute(async, &block) end end |