Module: SolidCache::Store::Connections

Included in:
SolidCache::Store
Defined in:
lib/solid_cache/store/connections.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#shard_optionsObject (readonly)

Returns the value of attribute shard_options.



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

def shard_options
  @shard_options
end

Instance Method Details

#connectionsObject



37
38
39
# File 'lib/solid_cache/store/connections.rb', line 37

def connections
  @connections ||= SolidCache::Connections.from_config(@shard_options)
end

#initialize(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/solid_cache/store/connections.rb', line 8

def initialize(options = {})
  super(options)
  if options[:clusters].present?
    if options[:clusters].size > 1
      raise ArgumentError, "Multiple clusters are no longer supported"
    else
      ActiveSupport.deprecator.warn(":clusters is deprecated, use :shards instead.")
    end
    @shard_options = options.fetch(:clusters).first[:shards]
  elsif options[:cluster].present?
    ActiveSupport.deprecator.warn(":cluster is deprecated, use :shards instead.")
    @shard_options = options.fetch(:cluster, {})[:shards]
  else
    @shard_options = options.fetch(:shards, nil)
  end

  if [ Array, NilClass ].none? { |klass| @shard_options.is_a? klass }
    raise ArgumentError, "`shards` is a `#{@shard_options.class.name}`, it should be Array or nil"
  end
end

#with_each_connection(async: false, &block) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/solid_cache/store/connections.rb', line 29

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