Class: RedisHA::ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_ha/connection_pool.rb

Constant Summary collapse

DEFAULT_READ_TIMEOUT =

timeout after which a redis connection is considered down. the default is 500ms

0.5
DEFAULT_RETRY_TIMEOUT =

timeout after which a redis that was marked as down is retried the default is 5s

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnectionPool

Returns a new instance of ConnectionPool.



13
14
15
16
17
18
# File 'lib/redis_ha/connection_pool.rb', line 13

def initialize
  @read_timeout  = DEFAULT_READ_TIMEOUT
  @retry_timeout = DEFAULT_RETRY_TIMEOUT

  @connections = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*msg) ⇒ Object



27
28
29
30
31
# File 'lib/redis_ha/connection_pool.rb', line 27

def method_missing(*msg)
  msg = msg.map(&:to_s)
  req = RedisHA::Protocol.request(*msg)
  execute(req)
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



11
12
13
# File 'lib/redis_ha/connection_pool.rb', line 11

def connections
  @connections
end

#read_timeoutObject

Returns the value of attribute read_timeout.



11
12
13
# File 'lib/redis_ha/connection_pool.rb', line 11

def read_timeout
  @read_timeout
end

#retry_timeoutObject

Returns the value of attribute retry_timeout.



11
12
13
# File 'lib/redis_ha/connection_pool.rb', line 11

def retry_timeout
  @retry_timeout
end

Instance Method Details

#connect(*conns) ⇒ Object



20
21
22
23
24
25
# File 'lib/redis_ha/connection_pool.rb', line 20

def connect(*conns)
  conns.each do |conn|
    @connections << RedisHA::Connection.new(conn, self)
    @connections.last.yield_connect
  end
end