<commit_before>module Rackdis
  class RedisFacade
    attr_reader :redis
    
    def initialize(redis, config, log)
      @redis  = redis
      @config = config
      @log    = log
    end
    
    def call(command, args)
      command.downcase!
      command = command.to_sym
      valid_command! command
      
      @log.info("redis> #{command} #{args.join(' ')}")
      args = Rackdis::ArgumentParser.new(command).process(args)
      
      @log.debug("API => REDIS: "+{command: command, args: args}.inspect)
      
      begin
        result = @redis.send(command, *args)
      rescue ArgumentError
        raise NotImplementedError, "Oops sorry - too beta - this needs fixing.  A bug report at https://github.com/penguinpowernz/rackdis/issues would be nice :)"
      end
      
      return Rackdis::ResponseBuilder.new(command).process(args, result)
    end
    
    def batch(commands)
      raise ArgumentError, "Batching is disabled" unless @config[:allow_batching]
      
      # Try to extract individual commands
      begin
        commands = JSON.parse(commands)
      rescue JSON::ParserError
        raise ArgumentError, "Invalid batch commands" unless commands.is_a? String<commit_msg>stopped borking the whole server when redis was given invalid args<commit_after>module Rackdis
  class RedisFacade
    attr_reader :redis
    
    def initialize(redis, config, log)
      @redis  = redis
      @config = config
      @log    = log
    end
    
    def call(command, args)
      command.downcase!
      command = command.to_sym
      valid_command! command
      
      @log.info("redis> #{command} #{args.join(' ')}")
      args = Rackdis::ArgumentParser.new(command).process(args)
      
      @log.debug("API => REDIS: "+{command: command, args: args}.inspect)
      
      result = @redis.send(command, *args)
      
      return Rackdis::ResponseBuilder.new(command).process(args, result)
    end
    
    def batch(commands)
      raise ArgumentError, "Batching is disabled" unless @config[:allow_batching]
      
      # Try to extract individual commands
      begin
        commands = JSON.parse(commands)
      rescue JSON::ParserError
        raise ArgumentError, "Invalid batch commands" unless commands.is_a? String
{'fraction_non_alphanumeric': 0.09746328437917223, 'fraction_numerical': 0.0, 'mean_word_length': 2.573926868044515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, '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': '212960', 'n_tokens_mistral': 656, 'n_tokens_neox': 654, 'n_words': 170}