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

[QUESTION] redis asyncio-compatible? #130

Open
larsclaussen opened this issue Mar 6, 2023 · 2 comments
Open

[QUESTION] redis asyncio-compatible? #130

larsclaussen opened this issue Mar 6, 2023 · 2 comments

Comments

@larsclaussen
Copy link

The docs state

Use redis as backend for the limiter
limiter = Limiter(key_func=get_remote_address, storage_uri="redis://:/n")

The limits async docs, however, say that you have to construct the uri like so

from limits.storage import storage_from_string
redis = storage_from_string("async+redis://localhost:6379")

I can't really tell if the implementation is asyncio-compatible currently, that is, changing the uri to async+redis will make it possible to decorate my async endpoint without blockking the event loop.

    @app.get("/mars")
    @limiter.limit("5/minute")
    async def homepage(request: Request, response: Response):
        return {"key": "value"}
@laurentS
Copy link
Owner

laurentS commented Mar 6, 2023

Hi @larsclaussen at the moment, the implementation is fully sync, so even if the async backend url works, slowapi won't be able to fully take advantage of it at the moment. The code you're after is probably this line. This is the oldest issue with the code #3 and nobody's gotten around to tackling it entirely yet (including myself 😅 )

@larsclaussen
Copy link
Author

Thanks for the clarification. Maybe a good idea to state that clearly in the readme. It is misleading because most examples are async examples and using a backend like redis (or any other of the backends stated) will result a in the whole event loop being blocked with every limit check.

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

2 participants