<commit_before>module Vanity
  module Adapters
    class << self
      # Creates new connection to Redis and returns RedisAdapter.
      #
      # @since 1.4.0
      def redis_connection(spec)
        require "redis/namespace"
        RedisAdapter.new(spec)
      end
    end

    # Redis adapter.
    #
    # @since 1.4.0
    class RedisAdapter < AbstractAdapter
      def initialize(options)
        @options = options.clone
        @options[:db] ||= @options[:database] || (@options[:path] && @options[:path].split("/")[1].to_i)
        @options[:thread_safe] = true
        connect!
      end

      def active?
        !!@redis
      end

      def disconnect!
        @redis.quit rescue nil if @redis
        @redis = nil
      end

      def reconnect!
        disconnect!
        connect!
      end

      def connect!
        @redis = @options[:redis] || Redis.new(@options)
        @metrics = Redis::Namespace.new("vanity:metrics", :redis=>@redis)
        @experiments = Redis::Namespace.new("vanity:experiments", :redis=>@redis)
      end

      def to_s
        @redis.id
      end

      def redis
        @redis<commit_msg>Fixed issue with latest redis-rb driver.<commit_after>module Vanity
  module Adapters
    class << self
      # Creates new connection to Redis and returns RedisAdapter.
      #
      # @since 1.4.0
      def redis_connection(spec)
        require "redis/namespace"
        RedisAdapter.new(spec)
      end
    end

    # Redis adapter.
    #
    # @since 1.4.0
    class RedisAdapter < AbstractAdapter
      def initialize(options)
        @options = options.clone
        @options[:db] ||= @options[:database] || (@options[:path] && @options.delete(:path).split("/")[1].to_i)
        @options[:thread_safe] = true
        connect!
      end

      def active?
        !!@redis
      end

      def disconnect!
        @redis.quit rescue nil if @redis
        @redis = nil
      end

      def reconnect!
        disconnect!
        connect!
      end

      def connect!
        @redis = @options[:redis] || Redis.new(@options)
        @metrics = Redis::Namespace.new("vanity:metrics", :redis=>@redis)
        @experiments = Redis::Namespace.new("vanity:experiments", :redis=>@redis)
      end

      def to_s
        @redis.id
      end

      def redis
        @redis
{'fraction_non_alphanumeric': 0.115684575389948, 'fraction_numerical': 0.006065857885615251, 'mean_word_length': 1.9793548387096773, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4211494', 'n_tokens_mistral': 731, 'n_tokens_neox': 706, 'n_words': 164}