mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 00:03:03 +08:00
Fix: if redis is not configured do not enable rate limit (#2027)
This commit is contained in:
parent
30aaf118e7
commit
4a7c0293f8
1 changed files with 3 additions and 1 deletions
|
@ -23,9 +23,11 @@ def check_bucket_limit(
|
|||
# Calculate current bucket time
|
||||
bucket_id = int(datetime.utcnow().timestamp()) % bucket_seconds
|
||||
bucket_lock_name = f"bl:{lock_name}:{bucket_id}"
|
||||
if not lock_redis:
|
||||
return
|
||||
try:
|
||||
value = lock_redis.incr(bucket_lock_name, bucket_seconds)
|
||||
if value > max_hits:
|
||||
raise werkzeug.exceptions.TooManyRequests()
|
||||
except redis.exceptions.RedisError:
|
||||
except (redis.exceptions.RedisError, AttributeError):
|
||||
log.e("Cannot connect to redis")
|
||||
|
|
Loading…
Reference in a new issue