Class: RedisKnock::Control
- Inherits:
-
Object
- Object
- RedisKnock::Control
- Defined in:
- lib/redis_knock/control.rb
Instance Method Summary collapse
- #allowed?(request) ⇒ Boolean
-
#initialize(args) ⇒ Control
constructor
A new instance of Control.
Constructor Details
#initialize(args) ⇒ Control
Returns a new instance of Control.
5 6 7 8 9 10 11 12 |
# File 'lib/redis_knock/control.rb', line 5 def initialize(args) = convert_keys_to_symbols args check! @client = get_connection [:redis] @limit = [:limit] @interval = [:interval] end |
Instance Method Details
#allowed?(request) ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'lib/redis_knock/control.rb', line 14 def allowed?(request) cache_key = get_cache_key request count = @client.incr cache_key @client.expire(cache_key, @interval) if count == 1 count <= @limit end |