Class: Watesan::FixedWindow
- Defined in:
- lib/watesan/fixed_window.rb
Instance Method Summary collapse
-
#call ⇒ Object
TODO: return with message.
-
#initialize(key:, options: Constants::DEFAULT_TORQUE_OPTIONS, redis_options: Constants::DEFAULT_REDIS_OPTIONS) ⇒ FixedWindow
constructor
A new instance of FixedWindow.
- #limit_reached? ⇒ Boolean
Methods inherited from Abstract
Constructor Details
#initialize(key:, options: Constants::DEFAULT_TORQUE_OPTIONS, redis_options: Constants::DEFAULT_REDIS_OPTIONS) ⇒ FixedWindow
Returns a new instance of FixedWindow.
6 7 8 9 |
# File 'lib/watesan/fixed_window.rb', line 6 def initialize(key:, options: Constants::DEFAULT_TORQUE_OPTIONS, redis_options: Constants::DEFAULT_REDIS_OPTIONS) init(, ) @key = key end |
Instance Method Details
#call ⇒ Object
TODO: return with message
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/watesan/fixed_window.rb', line 12 def call requests = @redis.get(@key).to_i if requests >= @options[:max_requests] true else @redis.multi do |multi| multi.incr(@key) multi.expire(@key, @options[:window_size]) end false end end |
#limit_reached? ⇒ Boolean
25 26 27 |
# File 'lib/watesan/fixed_window.rb', line 25 def limit_reached? call end |