FEATURE: optional default off global per ip rate limiter

This commit is contained in:
Sam
2017-12-11 17:21:00 +11:00
parent 3c230d8f97
commit 4986ebcf24
4 changed files with 132 additions and 1 deletions

View File

@ -28,6 +28,12 @@ class RateLimiter
$redis.delete_prefixed(RateLimiter.key_prefix)
end
def self.clear_all_global!
$redis.without_namespace.keys("GLOBAL::#{key_prefix}*").each do |k|
$redis.without_namespace.del k
end
end
def build_key(type)
"#{RateLimiter.key_prefix}:#{@user && @user.id}:#{type}"
end
@ -38,7 +44,7 @@ class RateLimiter
@key = build_key(type)
@max = max
@secs = secs
@global = false
@global = global
end
def clear!