Class: RedisMemo::Redis
- Inherits:
-
Redis::Distributed
- Object
- Redis::Distributed
- RedisMemo::Redis
- 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
-
#initialize(options = {}) ⇒ Redis
constructor
A new instance of Redis.
- #run_script(script_content, script_sha, *args) ⇒ Object
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( = {} # rubocop: disable Style/OptionHash ) clients = if .is_a?(Array) .map do |option| if option.is_a?(Array) RedisMemo::Redis::WithReplicas.new(option) else ::Redis.new(option) end end else [::Redis.new()] 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. != 'NOSCRIPT No matching script. Please use EVAL.' raise error end end eval(script_content, *args) # rubocop: disable Security/Eval end |