问题
I want to rate limit my Flask API. I found 2 solutions.
- The Flask-Limiter extension.
- A snippet from the Flask website using Redis: http://flask.pocoo.org/snippets/70/
What is the significance of Redis when Flask-Limiter is able to rate limit the request on the basis of remote address without Redis?
回答1:
Redis allows you to store the rate-limiting state in a persistent store.
This means you can:
- Restart your web server or web application and still have the rate-limitation work. You won't lose the records of the last requests made because of the working process being destroyed and a new one being created, instead.
- Use multiple web servers or web applications. This is because the rate-limitation state is stored in an external data store that also solves the issue of shared data synchronisation and data races. You can run as many web servers as you wish - the rate-limitation is shared among all of them.
- Look at the rate-limitation state. Redis offers easy CLI tools that allow you to look at the current active data in an ad-hoc manner, even MONITORing the incoming commands and requests.
- Let Redis manage TTL, LRU etc for rate-limitation algorithms. Redis supports this intrinsically.
来源:https://stackoverflow.com/questions/37949507/why-do-flask-rate-limiting-solutions-use-redis