Class: Berater::StaticLimiter

Inherits:
Limiter
  • Object
show all
Defined in:
lib/berater/static_limiter.rb

Constant Summary collapse

LUA_SCRIPT =
Berater::LuaScript(<<~LUA
  local key = KEYS[1]
  local capacity = tonumber(ARGV[1])
  local cost = tonumber(ARGV[2])

  local count = redis.call('GET', key) or 0
  local allowed = (count + cost) <= capacity

  if allowed then
    count = count + cost
    redis.call('SET', key, count)
  end

  return { tostring(count), allowed }
LUA
)

Instance Attribute Summary

Attributes inherited from Limiter

#capacity, #key, #options

Instance Method Summary collapse

Methods inherited from Limiter

#==, #limit, new, #redis, #utilization

Instance Method Details

#to_sObject



44
45
46
# File 'lib/berater/static_limiter.rb', line 44

def to_s
  "#<#{self.class}(#{key}: #{capacity})>"
end