Class: Limit::FixedWindowRateLimiter

Inherits:
BaseRateLimiter show all
Defined in:
lib/limit.rb

Overview

Fixed Window Rate Limiter, allows n of request in a fixed window ALERT: There is a chance of bursts/spike in this method, so use it with caution

Constant Summary

Constants inherited from BaseRateLimiter

BaseRateLimiter::REQUIRED_KEYS

Instance Attribute Summary

Attributes inherited from BaseRateLimiter

#identifier_prefix, #limit_calculator

Instance Method Summary collapse

Methods inherited from BaseRateLimiter

connection, #get_key, #initialize, load_script, logger

Constructor Details

This class inherits a constructor from Limit::BaseRateLimiter

Instance Method Details

#allowed?(key) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
153
154
155
156
157
158
159
160
# File 'lib/limit.rb', line 150

def allowed?(key)
  limit_data = get_current_limit(key)
  result = eval_sha(
    [get_key(key)],
    [
      limit_data[:window_seconds],
      limit_data[:max_requests]
    ]
  )
  result == 1
end