<commit_before>require File.expand_path '../redis', File.dirname(__FILE__)

class Redis
  
  module Send
    
    def send_redis data
      collect = []
      if nil == data
        collect << "$-1\r\n"
      elsif false == data
        collect << ":0\r\n"
      elsif true == data
        collect << ":1\r\n"
      elsif Float === data and data.nan?
        collect << ":0\r\n"
      elsif Float === data and data.infinite? || 0 > 0
        collect << ":inf\r\n"
      elsif Float === data and data.infinite? || 0 < 0
        collect << ":-inf\r\n"
      elsif Hash === data
        collect << "*#{data.size * 2}\r\n"
        data.each do |key, value|
          key = key.to_s
          value = value.to_s
          collect << "$#{key.bytesize}\r\n"
          collect << key
          collect << "\r\n$#{value.bytesize}\r\n"
          collect << value
          collect << "\r\n"
        end
      elsif Enumerable === data and !(String === data)
        collect << "*#{data.size}\r\n"
        data.each do |element|
          element = element.to_s
          collect << "$#{element.bytesize}\r\n"
          collect << element
          collect << "\r\n"
        end
      else
        data = data.to_s
        collect << "$#{data.bytesize}\r\n"
        collect << data
        collect << "\r\n"
      end
      send_data collect.join
    end
    
  end
    
end
<commit_msg>faster and nicer<commit_after>require File.expand_path '../redis', File.dirname(__FILE__)

class Redis
  
  module Send
    
    def send_redis data
      collect = []
      if nil == data
        collect << "$-1"
      elsif false == data
        collect << ":0"
      elsif true == data
        collect << ":1"
      elsif Float === data and data.nan?
        collect << ":0"
      elsif Float === data and data.infinite? || 0 > 0
        collect << ":inf"
      elsif Float === data and data.infinite? || 0 < 0
        collect << ":-inf"
      elsif Hash === data
        collect << "*#{data.size * 2}"
        data.each do |key, value|
          key = key.to_s
          value = value.to_s
          collect << "$#{key.bytesize}"
          collect << key
          collect << "$#{value.bytesize}"
          collect << value
        end
      elsif Enumerable === data and !(String === data)
        collect << "*#{data.size}"
        data.each do |element|
          element = element.to_s
          collect << "$#{element.bytesize}"
          collect << element
        end
      else
        data = data.to_s
        collect << "$#{data.bytesize}"
        collect << data
      end
      collect << ''
      send_data collect.join "\r\n"
    end
    
  end
    
end

{'fraction_non_alphanumeric': 0.14501510574018128, 'fraction_numerical': 0.006797583081570997, 'mean_word_length': 1.5471153846153847, 'pattern_counts': {'":': 10, '<': 77, '<?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': '6672476', 'n_tokens_mistral': 818, 'n_tokens_neox': 817, 'n_words': 222}