<commit_before>class Redis
  unless defined?(::BasicObject)
    class BasicObject
      instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A(__|instance_eval)/ }
    end
  end

  class Pipeline
    attr :futures

    def initialize
      @without_reconnect = false
      @shutdown = false
      @futures = []
    end

    def without_reconnect?
      @without_reconnect
    end

    def shutdown?
      @shutdown
    end

    def call(command, &block)
      # A pipeline that contains a shutdown should not raise ECONNRESET when
      # the connection is gone.
      @shutdown = true if command.first == :shutdown
      future = Future.new(command, block)
      @futures << future
      future
    end

    def call_pipeline(pipeline)
      @shutdown = true if pipeline.shutdown?
      @futures.concat(pipeline.futures)
      nil
    end

    def commands
      @futures.map { |f| f._command }
    end

    def without_reconnect(&block)
      @without_reconnect = true
      yield
    end

    def finish(replies)
      futures.each_with_index.map do |future, i|
        future._set(replies[i])
      end
    end

    class Multi < self
      def finish(replies)
        return if replies.last.nil? # The transaction failed because of WATCH.

        if replies.last.size < futures.size - 2
          # Some command wasn't recognized by Redis.
          raise replies.detect { |r| r.kind_of?(::RuntimeError) }
        end

        super(replies.last)
      end

      def commands
        [[:multi]] + super + [[:exec]]
      end
    end
  end

  class FutureNotReady < RuntimeError
    def initialize
      super("Value will be available once the pipeline executes.")
    end
  end

  class Future < BasicObject
    FutureNotReady = ::Redis::FutureNotReady.new

    def initialize(command, transformation)
      @command = command
      @transformation = transformation
      @object = FutureNotReady
    end
<commit_msg>Transform RuntimeError to CommandError<commit_after>class Redis
  unless defined?(::BasicObject)
    class BasicObject
      instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A(__|instance_eval)/ }
    end
  end

  class Pipeline
    attr :futures

    def initialize
      @without_reconnect = false
      @shutdown = false
      @futures = []
    end

    def without_reconnect?
      @without_reconnect
    end

    def shutdown?
      @shutdown
    end

    def call(command, &block)
      # A pipeline that contains a shutdown should not raise ECONNRESET when
      # the connection is gone.
      @shutdown = true if command.first == :shutdown
      future = Future.new(command, block)
      @futures << future
      future
    end

    def call_pipeline(pipeline)
      @shutdown = true if pipeline.shutdown?
      @futures.concat(pipeline.futures)
      nil
    end

    def commands
      @futures.map { |f| f._command }
    end

    def without_reconnect(&block)
      @without_reconnect = true
      yield
    end

    def finish(replies, &blk)
      if blk
        futures.each_with_index.map do |future, i|
          future._set(blk.call(replies[i]))
        end
      else
        futures.each_with_index.map do |future, i|
          future._set(replies[i])
        end
      end
    end

    class Multi < self
      def finish(replies)
        return if replies.last.nil? # The transaction failed because of WATCH.

        if replies.last.size < futures.size - 2
          # Some command wasn't recognized by Redis.
          raise replies.detect { |r| r.kind_of?(::RuntimeError) }
        end

        super(replies.last) do |reply|
          # Because an EXEC returns nested replies, hiredis won't be able to
          # convert an error reply to a CommandError instance itself. This is
          # specific to MULTI/EXEC, so we solve this here.
          reply.is_a?(::RuntimeError) ? CommandError.new(reply.message) : reply
        end
      end

      def commands
        [[:multi]] + super + [[:exec]]
      end
    end
  end

  class FutureNotReady < RuntimeError
    def initialize
      super("Value will be available once the pipeline executes.")
    end
  end

  class Future < BasicObject
    FutureNotReady = ::Redis::FutureNotReady.new

    def initialize(command, transformation)
      @command = command
      @transformation = transformation
      @object = FutureNotReady
    end

{'fraction_non_alphanumeric': 0.08007320979180965, 'fraction_numerical': 0.0004575611988103409, 'mean_word_length': 2.2385185185185184, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, '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': '6398719', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1270, 'n_words': 376}