Class: Rack::ECG::Check::RedisConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ecg/check/redis_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ RedisConnection

Checks whether the given Redis client is currently connected to the database as identified by the instance option.

Parameters:

  • parameters (Hash) (defaults to: {})

    a customizable set of options

Options Hash (parameters):

  • instance (Redis)

    The Redis client



13
14
15
# File 'lib/rack/ecg/check/redis_connection.rb', line 13

def initialize(parameters = {})
  @redis_instance = parameters[:instance]
end

Instance Attribute Details

#redis_instanceObject (readonly)

Returns the value of attribute redis_instance.



7
8
9
# File 'lib/rack/ecg/check/redis_connection.rb', line 7

def redis_instance
  @redis_instance
end

Instance Method Details

#resultObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rack/ecg/check/redis_connection.rb', line 17

def result
  value = ""
  status = Status::OK
  begin
    if redis_instance.nil?
      status = Status::ERROR
      value = "Redis instance parameters not found"
    elsif defined?(::Redis)
      value = redis_instance.connected?
      status = value ? Status::OK : Status::ERROR
    else
      status = Status::ERROR
      value = "Redis not found"
    end
  rescue => e
    status = Status::ERROR
    value = e.message
  end

  Result.new(:redis, status, value.to_s)
end