Why do Flask rate limiting solutions use Redis?

谁说我不能喝 提交于 2020-01-01 15:03:19

问题


I want to rate limit my Flask API. I found 2 solutions.

  1. The Flask-Limiter extension.
  2. 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!