<commit_before>require "redis/connection/registry"
require "redis/connection/command_helper"
require "redis/errors"
require "socket"

class Redis
  module Connection
    module SocketMixin

      CRLF = "\r\n".freeze

      def initialize(*args)
        super(*args)

        @timeout = nil
        @buffer = ""
      end

      def timeout=(timeout)
        if timeout && timeout > 0
          @timeout = timeout
        else
          @timeout = nil
        end
      end

      def read(nbytes)
        result = @buffer.slice!(0, nbytes)

        while result.bytesize < nbytes
          result << _read_from_socket(nbytes - result.bytesize)
        end

        result
      end

      def gets
        crlf = nil
        start = 0

        while (crlf = @buffer.index(CRLF, start)) == nil
          start = @buffer.bytesize
          @buffer << _read_from_socket(16384)
        end

        @buffer.slice!(0, crlf + CRLF.bytesize)<commit_msg>Passing start to String#index breaks things<commit_after>require "redis/connection/registry"
require "redis/connection/command_helper"
require "redis/errors"
require "socket"

class Redis
  module Connection
    module SocketMixin

      CRLF = "\r\n".freeze

      def initialize(*args)
        super(*args)

        @timeout = nil
        @buffer = ""
      end

      def timeout=(timeout)
        if timeout && timeout > 0
          @timeout = timeout
        else
          @timeout = nil
        end
      end

      def read(nbytes)
        result = @buffer.slice!(0, nbytes)

        while result.bytesize < nbytes
          result << _read_from_socket(nbytes - result.bytesize)
        end

        result
      end

      def gets
        crlf = nil

        while (crlf = @buffer.index(CRLF)) == nil
          @buffer << _read_from_socket(1024)
        end

        @buffer.slice!(0, crlf + CRLF.bytesize)
{'fraction_non_alphanumeric': 0.09339774557165861, 'fraction_numerical': 0.008588298443370907, 'mean_word_length': 1.8414634146341464, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2201582', 'n_tokens_mistral': 579, 'n_tokens_neox': 536, 'n_words': 137}