Skip to content

Commit

Permalink
Merge pull request #33 from Yangruipis/master
Browse files Browse the repository at this point in the history
fix: redis reconnection error
  • Loading branch information
long2ice authored Jun 5, 2023
2 parents 3198d2f + d6520e8 commit c9bcaab
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fastapi_limiter/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from starlette.requests import Request
from starlette.responses import Response
from starlette.websockets import WebSocket
import redis as pyredis

from fastapi_limiter import FastAPILimiter

Expand Down Expand Up @@ -49,7 +50,13 @@ async def __call__(self, request: Request, response: Response):
callback = self.callback or FastAPILimiter.http_callback
rate_key = await identifier(request)
key = f"{FastAPILimiter.prefix}:{rate_key}:{route_index}:{dep_index}"
pexpire = await self._check(key)
try:
pexpire = await self._check(key)
except pyredis.exceptions.NoScriptError:
FastAPILimiter.lua_sha = await FastAPILimiter.redis.script_load(
FastAPILimiter.lua_script
)
pexpire = await self._check(key)
if pexpire != 0:
return await callback(request, response, pexpire)

Expand Down

0 comments on commit c9bcaab

Please sign in to comment.