Class: EventMachine::Hiredis::Sentinel::RedisClient

Inherits:
Client
  • Object
show all
Defined in:
lib/em-hiredis-sentinel/redis_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(sentinels: [], master_name: 'mymaster', db: 0, password: nil) ⇒ RedisClient

Returns a new instance of RedisClient.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/em-hiredis-sentinel/redis_client.rb', line 7

def initialize(sentinels:[], master_name:'mymaster', db:0, password:nil)
  @master_name = master_name
  @sentinels = _parse_sentinel_options(sentinels)
  #p @sentinels
  raise "Need at least 1 sentinel" if @sentinels.nil? || @sentinels.count < 1
  @sentinels.uniq! {|h| h.values_at(:host, :port) }
  @sentinels.shuffle! #try to randomize

  init_sentinel_client

  super(nil, nil, password, db)
  init_master_client

  #waits for connect to do anything
end

Instance Method Details

#connect(with_pubsub: false) ⇒ Object



34
35
36
37
38
# File 'lib/em-hiredis-sentinel/redis_client.rb', line 34

def connect(with_pubsub:false)
  @with_pubsub ||= with_pubsub
  try_next_sentinel
  self
end

#pubsubObject

override bc of auto .connect in super



24
25
26
27
28
29
30
31
32
# File 'lib/em-hiredis-sentinel/redis_client.rb', line 24

def pubsub
  #EM::Hiredis.logger.debug("pubsub")
  @pubsub ||= begin
    @with_pubsub = true
    init_master_pubsub_client
    update_master_pubsub_client(@master_client.host, @master_client.port) if @master_client.connected?
    @master_pubsub_client
  end
end

#super_connectObject

to ref super’s connect



5
# File 'lib/em-hiredis-sentinel/redis_client.rb', line 5

alias :super_connect :connect