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.



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

def initialize(
  options = {} # rubocop: disable Style/OptionHash
)
  clients =
    if options.is_a?(Array)
      options.map do |option|
        if option.is_a?(Array)
          RedisMemo::Redis::WithReplicas.new(option)
        else
          ::Redis.new(option)
        end
      end
    else
      [::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

Instance Method Details

#run_script(script_content, script_sha, *args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/redis_memo/redis.rb', line 34

def run_script(script_content, script_sha, *args)
  begin
    return evalsha(script_sha, *args) if script_sha
  rescue Redis::CommandError => error
    if error.message != 'NOSCRIPT No matching script. Please use EVAL.'
      raise error
    end
  end
  eval(script_content, *args) # rubocop: disable Security/Eval
end