You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From reading the code, the following comment indicates that Redis Pattern: Rate Limiter 1 is being used which is confusing as the cache key does not contain the timestamp.
My understanding is that in-fact a variation of Redis Pattern: Rate Limiter 2 is being used as a by-product of the NX command.
Is this understanding correct? If so - would be useful to update the comment.
Attaching the reference patterns
Pattern 1
FUNCTION LIMIT_API_CALL(ip)
ts = CURRENT_UNIX_TIME()
keyname = ip+":"+ts
MULTI
INCR(keyname)
EXPIRE(keyname,10)
EXEC
current = RESPONSE_OF_INCR_WITHIN_MULTI
IF current > 10 THEN
ERROR "too many requests per second"
ELSE
PERFORM_API_CALL()
END
Pattern 2
FUNCTION LIMIT_API_CALL(ip):
current = GET(ip)
IF current != NULL AND current > 10 THEN
ERROR "too many requests per second"
ELSE
value = INCR(ip)
IF value == 1 THEN
EXPIRE(ip,1)
END
PERFORM_API_CALL()
END
The text was updated successfully, but these errors were encountered:
From reading the code, the following comment indicates that
Redis Pattern: Rate Limiter 1
is being used which is confusing as the cache key does not contain the timestamp.My understanding is that in-fact a variation of
Redis Pattern: Rate Limiter 2
is being used as a by-product of theNX
command.Is this understanding correct? If so - would be useful to update the comment.
Attaching the reference patterns
Pattern 1
Pattern 2
The text was updated successfully, but these errors were encountered: