<commit_before>require 'json'
require 'logster/base_store'

module Logster
  class RedisRateLimiter
    BUCKETS = 6
    PREFIX = "__LOGSTER__RATE_LIMIT".freeze

    def initialize(redis, severities, limit, duration, redis_prefix = nil, callback = nil)
      @severities = severities
      @limit = limit
      @duration = duration
      @callback = callback
      @redis_prefix = redis_prefix
      @redis = redis
      @bucket_range = @duration / BUCKETS
      @mget_keys = (0..(BUCKETS - 1)).map { |i| "#{key}:#{i}" }
    end

    def retrieve_rate
      @redis.mget(@mget_keys).reduce(0) { |sum, value| sum + value.to_i }<commit_msg>Add `att_reader` to duration.<commit_after>require 'json'
require 'logster/base_store'

module Logster
  class RedisRateLimiter
    BUCKETS = 6
    PREFIX = "__LOGSTER__RATE_LIMIT".freeze

    attr_reader :duration

    def initialize(redis, severities, limit, duration, redis_prefix = nil, callback = nil)
      @severities = severities
      @limit = limit
      @duration = duration
      @callback = callback
      @redis_prefix = redis_prefix
      @redis = redis
      @bucket_range = @duration / BUCKETS
      @mget_keys = (0..(BUCKETS - 1)).map { |i| "#{key}:#{i}" }
    end

    def retrieve_rate
      @redis.mget(@mget_keys).reduce(0) { |sum, value| sum + value.to_i }
{'fraction_non_alphanumeric': 0.11863117870722434, 'fraction_numerical': 0.006083650190114068, 'mean_word_length': 3.0617283950617282, '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': '2613797', 'n_tokens_mistral': 456, 'n_tokens_neox': 446, 'n_words': 103}