File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,10 +16,10 @@ def _rate_per_second(function):
1616 def __rate_per_second (* args , ** kwargs ):
1717 client = get_redis_client ()
1818 key = f"rate-limit:{ int (time .time ())} "
19- if client .incr (key ) > count :
20- if client .ttl (key ) == - 1 : # timeout is not set
21- client .expire (key , 1 ) # expire in 1 second
19+ if int (client .incr (key )) > count :
2220 raise RateLimitExceeded
21+ if client .ttl (key ) == - 1 : # timeout is not set
22+ client .expire (key , 1 ) # expire in 1 second
2323 return function (* args , * kwargs )
2424 return __rate_per_second
2525 return _rate_per_second
Original file line number Diff line number Diff line change 1414def rate_per_second (function , count ):
1515 client = get_redis_client ()
1616 key = f"rate-limit:{ int (time .time ())} "
17- if client .incr (key ) > count :
18- if client .ttl (key ) == - 1 : # timeout is not set
19- client .expire (key , 1 ) # expire in 1 second
17+ if int (client .incr (key )) > count :
2018 raise RateLimitExceeded
19+ if client .ttl (key ) == - 1 : # timeout is not set
20+ client .expire (key , 1 ) # expire in 1 second
2121 return function ()
2222
2323
You can’t perform that action at this time.
0 commit comments