module CableX::Cable::RateLimit::CheckRateLimit

Process Rate Limit

Public Instance Methods

check_rate_limit() click to toggle source
# File lib/cable_x/cable/rate_limit/rate_limit.rb, line 13
def check_rate_limit
  check_unit('second') || check_unit('minute') || check_unit('hour')
end
check_unit(unit) click to toggle source
# File lib/cable_x/cable/rate_limit/rate_limit.rb, line 17
def check_unit(unit)
  check_value = rate_limit[unit.to_s.to_sym]
  return unless check_value

  key = device_key unit
  redis_set key, 0, 1.send(unit) * 1000 unless redis_exists(key)
  redis_incr key
  block_connection = (redis_get(key) || -1).to_i >= check_value
  return unless block_connection

  block_device unit
end
do_rate_limit() click to toggle source
# File lib/cable_x/cable/rate_limit/rate_limit.rb, line 9
def do_rate_limit
  check_rate_limit if rate_limit
end