Class: EventMachine::Hiredis::Sentinel::RedisClient
- Inherits:
-
Client
- Object
- Client
- EventMachine::Hiredis::Sentinel::RedisClient
- Defined in:
- lib/em-hiredis-sentinel/redis_client.rb
Instance Method Summary collapse
- #connect(with_pubsub: false) ⇒ Object
-
#initialize(sentinels: [], master_name: 'mymaster', db: 0, password: nil) ⇒ RedisClient
constructor
A new instance of RedisClient.
-
#pubsub ⇒ Object
override bc of auto .connect in super.
-
#super_connect ⇒ Object
to ref super’s connect.
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 = (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 |
#pubsub ⇒ Object
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_connect ⇒ Object
to ref super’s connect
5 |
# File 'lib/em-hiredis-sentinel/redis_client.rb', line 5 alias :super_connect :connect |