Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the behavior if Redis is unavailable? #54

Open
stephen-lazarionok opened this issue Mar 6, 2024 · 3 comments
Open

What is the behavior if Redis is unavailable? #54

stephen-lazarionok opened this issue Mar 6, 2024 · 3 comments

Comments

@stephen-lazarionok
Copy link

No description provided.

@zulrang
Copy link

zulrang commented Mar 19, 2024

From experience, any calls to your endpoints fail

lib/python3.11/site-packages/redis/_parsers/base.py", line 221, in _readline
    raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
redis.exceptions.ConnectionError: Connection closed by server.

@benglewis
Copy link

Is there any plan to fix this?

@bashtian-fr
Copy link

what i did is just add an exception that return 0 for pexpire if redis is unavailable in depends:RateLimiter class:

    async def _check(self, key):
        redis = FastAPILimiter.redis
        try:
            pexpire = await redis.evalsha(
                FastAPILimiter.lua_sha, 1, key, str(self.times), str(self.milliseconds)
            )
        except:
            logger.exception("Redis is unavaible - ratelimiter disabled")
            return 0
        return pexpire

prolly not the best way, it was a 5minutes craft for when I have maintenance to do, hope that helps,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants