<commit_before># Simple mock Redis library. Only implements GET, INCR, MGET, KEYS, and
# EXPIRE. (EXPIRE is implemented as a noop, so don't rely on it.)

class MockRedis
  def initialize
    reset!
  end

  def reset!
    @data = {}
  end

  def incr(key)
    @data[key] ||= 0
    @data[key] += 1
  end

  def get(key)
    @data[key]
  end

  def keys(pattern)
    # pattern is a Redis-style pattern, not a Ruby regexp.
    re = regex_from_redis_pattern(pattern)
    @data.keys.find_all {|k| k =~ re}
  end

  def mget(*keys)
    keys.map {|k| @data[k]}
  end

  def expire(key, seconds)
    1
  end

  private
  def regex_from_redis_pattern(pattern)
    # TODO: respect \ as escape character
    pattern.
      gsub('?', '.').
      gsub('*', '.*')
  end
end<commit_msg>Match Redis behavior for expiry of non-existent keys<commit_after># Simple mock Redis library. Only implements GET, INCR, MGET, KEYS, and
# EXPIRE. (EXPIRE is implemented as a noop, so don't rely on it.)

class MockRedis
  def initialize
    reset!
  end

  def reset!
    @data = {}
  end

  def incr(key)
    @data[key] ||= 0
    @data[key] += 1
  end

  def get(key)
    @data[key]
  end

  def keys(pattern)
    # pattern is a Redis-style pattern, not a Ruby regexp.
    re = regex_from_redis_pattern(pattern)
    @data.keys.find_all {|k| k =~ re}
  end

  def mget(*keys)
    keys.map {|k| @data[k]}
  end

  def expire(key, seconds)
    @data[key] ? 1 : 0
  end

  private
  def regex_from_redis_pattern(pattern)
    # TODO: respect \ as escape character
    pattern.
      gsub('?', '.').
      gsub('*', '.*')
  end
end
{'fraction_non_alphanumeric': 0.12640801001251564, 'fraction_numerical': 0.004380475594493116, 'mean_word_length': 2.642369020501139, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6494999', 'n_tokens_mistral': 624, 'n_tokens_neox': 597, 'n_words': 182}