Sha256: ed4aa01136838e306c3cecb5f4be9d0e8f69d2ca7f4a3f9c946cc6ab88ebec8b

Contents?: true

Size: 715 Bytes

Versions: 5

Compression:

Stored size: 715 Bytes

Contents

require "redis"

module Easymon
  class RedisWriteableCheck
    attr_accessor :config

    def initialize(config)
      self.config = config
    end

    def check
      check_status = redis_writeable?
      message = check_status ? "Writeable" : "Read Only"

      [check_status, message]
    end

    private
      def redis_writeable?
        redis = Redis.new(@config)
        key = "easymon_#{Time.now.to_i}"
        reply = redis.set(key, "true")
        redis.del(key)

        reply == "OK"
      rescue
        false
      ensure
        if redis.respond_to? :close
          redis.close              # Redis 4+
        else
          redis.client.disconnect  # Older redis
        end
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easymon-1.6.3 lib/easymon/checks/redis_writeable_check.rb
easymon-1.6.2 lib/easymon/checks/redis_writeable_check.rb
easymon-1.6.1 lib/easymon/checks/redis_writeable_check.rb
easymon-1.5 lib/easymon/checks/redis_writeable_check.rb
easymon-1.6.0 lib/easymon/checks/redis_writeable_check.rb