Sha256: 913ca6d249fe5c6412faa737896ce5818f6d01b293271ef6c5baa2c4b8bc241b

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Rack
  class ECG
    module Check
      class RedisConnection
        attr_reader :redis_instance

        # Checks whether the given Redis client is currently connected to the
        # database as identified by the ++instance++ option.
        #
        # @option parameters instance [Redis] The Redis client
        def initialize(parameters = {})
          @redis_instance = parameters[:instance]
        end

        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

        CheckRegistry.instance.register(:redis, RedisConnection)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-ecg-0.3.0 lib/rack/ecg/check/redis_connection.rb