Class: Kredis::Types::Limiter
- Defined in:
- lib/kredis/types/limiter.rb
Overview
A limiter is a specialized form of a counter that can be checked whether it has been exceeded and is provided fail safe. This means it can be used to guard login screens from brute force attacks without denying access in case Redis is offline.
It will usually be used as an expiring limiter. Note that the limiter expires in total after the ‘expires_in` time used upon the first poke.
It offers no guarentee that you can’t poke yourself above the limit. You’re responsible for checking ‘#exceeded?` yourself first, and this may produce a race condition. So only use this when the exact number of pokes is not critical.
Defined Under Namespace
Classes: LimitExceeded
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
Attributes inherited from Counter
Attributes inherited from Proxying
Instance Method Summary collapse
Methods inherited from Counter
#decrement, #increment, #reset, #value
Methods included from DefaultValues
Methods inherited from Proxying
#failsafe, #initialize, proxying, #unproxied_redis
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
11 12 13 |
# File 'lib/kredis/types/limiter.rb', line 11 def limit @limit end |
Instance Method Details
#exceeded? ⇒ Boolean
19 20 21 22 23 |
# File 'lib/kredis/types/limiter.rb', line 19 def exceeded? failsafe returning: false do value >= limit end end |
#poke ⇒ Object
13 14 15 16 17 |
# File 'lib/kredis/types/limiter.rb', line 13 def poke failsafe returning: true do increment end end |