<commit_before>class Readis
  class Inspect < Readis


    def initialize(*args)
      super
      @redis = Redis.new(:host => self.options[:host], :port => self.options[:port])
    end

    def parser
      optparser = super
      optparser.banner = <<-BANNER

Usage: readis inspect [options]

      BANNER
      optparser
    end

    def execute_command(input_string)
      parts = input_string.split(" ")
      redis_command = parts.shift
  
      if redis_command
        redis_command.downcase!
      end
  
      whitelist = %w(
        exists get hexists hget hgetall hkeys hlen hmget hvals
        info lindex llen lrange mget randomkey scard sdiff
        sinter sismember smembers srandmember strlen sunion
        ttl type zcard zcount zrange zrangebyscore zrank
        zrevrange zrevrangebyscore zrevrank zscore
      )
  
      case redis_command
      when nil
        # do nothing
      when *whitelist
        @redis.send(redis_command, *parts)
      when "exit", "quit"
        exit
      else
        'Unknown Redis command'
      end
    end

  
    def run
      loop do
        print "readis #{self.options[:host]}:#{self.options[:port]}> "
        input_string = gets.chomp
        begin
          out = execute_command(input_string)
          case out
          when nil
            # do nothing
          else
            puts out.inspect
          end
        rescue => error
          puts error.inspect
        end
      end
    end
  
  end
end
<commit_msg>whitelisted KEYS; more todo notes<commit_after>class Readis
  class Inspect < Readis


    def initialize(*args)
      super
      @redis = Redis.new(:host => self.options[:host], :port => self.options[:port])
    end

    def parser
      optparser = super
      optparser.banner = <<-BANNER

Usage: readis inspect [options]

      BANNER
      optparser
    end

    def execute_command(input_string)
      parts = input_string.split(" ")
      redis_command = parts.shift
  
      if redis_command
        redis_command.downcase!
      end
  
      whitelist = %w(
        keys
        exists get hexists hget hgetall hkeys hlen hmget hvals
        info lindex llen lrange mget randomkey scard sdiff
        sinter sismember smembers srandmember strlen sunion
        ttl type zcard zcount zrange zrangebyscore zrank
        zrevrange zrevrangebyscore zrevrank zscore
      )
  
      case redis_command
      when nil
        # do nothing
      when *whitelist
        @redis.send(redis_command, *parts)
      when "exit", "quit"
        exit
      else
        'Unknown Redis command'
      end
    end

  
    def run
      loop do
        print "readis #{self.options[:host]}:#{self.options[:port]}> "
        input_string = gets.chomp
        # TODO: tab completion.  Example implementation in automatthew/flipper
        # https://github.com/automatthew/flipper/blob/master/lib/flipper.rb
        # Inititally, we should only try to complete using the list of command
        # names, but we may later consider adding keys, fields, member names, etc.
        # discovered through commands issued.
        begin
          out = execute_command(input_string)
          case out
          when nil
            # do nothing
          else
            # TODO: consider the formatting.  Do we want to mimic
            # the redis-cli output?
            puts out.inspect
          end
        rescue => error
          puts error.inspect
        end
      end
    end
  
  end
end

{'fraction_non_alphanumeric': 0.06422811059907835, 'fraction_numerical': 0.0, 'mean_word_length': 1.8351020408163266, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '3788380', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1021, 'n_words': 301}