<commit_before>require 'health_monitor/providers/base'
require 'redis/namespace'

module HealthMonitor
  module Providers
    class RedisException < StandardError; end

    class Redis < Base
      def check!
        time = Time.now.to_s(:db)

        r = ::Redis.new
        r.set(key, time)
        fetched = r.get(key)

        raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
      rescue => e
        raise RedisException.new(e.message)
      end

      private

      def key
        @key ||= ['health', request.try(:remote_ip)].join(':')
      end
    end
  end<commit_msg>Quickly disconnect redis.<commit_after>require 'health_monitor/providers/base'
require 'redis/namespace'

module HealthMonitor
  module Providers
    class RedisException < StandardError; end

    class Redis < Base
      def check!
        time = Time.now.to_s(:db)

        redis = ::Redis.new
        redis.set(key, time)
        fetched = redis.get(key)

        raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
      rescue => e
        raise RedisException.new(e.message)
      ensure
        redis.client.disconnect
      end

      private

      def key
        @key ||= ['health', request.try(:remote_ip)].join(':')
      end
    end
  end
{'fraction_non_alphanumeric': 0.11249030256012413, 'fraction_numerical': 0.0, 'mean_word_length': 2.3419689119170983, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4876061', 'n_tokens_mistral': 409, 'n_tokens_neox': 393, 'n_words': 101}