Class: RedisMemo::Redis

Inherits:
Redis::Distributed
  • Object
show all
Defined in:
lib/redis_memo/redis.rb

Overview

Redis::Distributed does not support reading from multiple read replicas. This class adds this functionality

Defined Under Namespace

Classes: WithReplicas

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/redis_memo/redis.rb', line 10

def initialize(options={})
  clients =
    if options.is_a?(Array)
      options.map do |option|
        if option.is_a?(Array)
          RedisMemo::Redis::WithReplicas.new(option)
        else
          option[:logger] ||= RedisMemo::DefaultOptions.logger
          ::Redis.new(option)
        end
      end
    else
      options[:logger] ||= RedisMemo::DefaultOptions.logger
      [::Redis.new(options)]
    end

  # Pass in our own hash ring to use the clients with multi-read-replica
  # support
  hash_ring = Redis::HashRing.new(clients)

  super([], ring: hash_ring)
end