Skip to content

Commit f39538f

Browse files
committed
Fix some keys with no timeout
1 parent 7ecfcf8 commit f39538f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

decorator_rate_limiting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

naive_rate_limiting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
def 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

0 commit comments

Comments
 (0)