class Heartcheck::Checks::Redis

Check for a redis service Base is set in heartcheck gem

Public Instance Methods

uri_info() click to toggle source

list services uri info

@return [Array]

# File lib/heartcheck/checks/redis.rb, line 22
def uri_info
  services.map do |s|
    opts = s[:connection].connection
    {
      host: opts[:host],
      port: opts[:port],
      scheme: 'redis'.freeze
    }
  end
end
validate() click to toggle source

validate each service

@retun [void]

# File lib/heartcheck/checks/redis.rb, line 9
def validate
  services.each do |service|
    connection = service[:connection]

    append_error(service[:name], :set) unless set?(connection)
    append_error(service[:name], :get) unless get?(connection)
    append_error(service[:name], :delete) unless del?(connection)
  end
end

Private Instance Methods

custom_error(name, key_error) click to toggle source

customize the error message It's called in Heartcheck::Checks::Base#append_error

@param name [String] An identifier of service @param key_error [Symbol] name of action

@return [void]

# File lib/heartcheck/checks/redis.rb, line 69
def custom_error(name, key_error)
  @errors << "#{name} fails to #{key_error}"
end
del?(con) click to toggle source

test if can delete on redis

@param con [Redis] an instance of redis

@return [Bollean]

# File lib/heartcheck/checks/redis.rb, line 58
def del?(con)
  con.del(unique_check_key) == 1
end
get?(con) click to toggle source

test if can read on redis

@param con [Redis] an instance of redis

@return [Bollean]

# File lib/heartcheck/checks/redis.rb, line 49
def get?(con)
  con.get(unique_check_key) == 'heartcheck'
end
set?(con) click to toggle source

test if can write on redis

@param con [Redis] an instance of redis

@return [Bollean]

# File lib/heartcheck/checks/redis.rb, line 40
def set?(con)
  con.set(unique_check_key, 'heartcheck') == 'OK'
end
unique_check_key() click to toggle source

generate an unique redis key It's necessary to run concurrent application instances/checks using a shared redis

@return [String]

# File lib/heartcheck/checks/redis.rb, line 78
def unique_check_key
  @unique_check_key ||= SecureRandom.hex
end