基于redis的python速率限制器。

tds-python-redis-rate-limit的Python项目详细描述


https://travis-ci.org/EvoluxBR/python-redis-rate-limit.svg?branch=masterhttps://img.shields.io/pypi/v/python-redis-rate-limit.svg

这个lib提供了在 redis=2.6.0。

示例:每秒10个请求

fromredis_rate_limitimportRateLimit,TooManyRequeststry:withRateLimit(resource='users_list',client='192.168.0.10',max_requests=10):return'200 OK'exceptTooManyRequests:return'429 Too Many Requests'

示例:每分钟600个请求

fromredis_rate_limitimportRateLimit,TooManyRequeststry:withRateLimit(resource='users_list',client='192.168.0.10',max_requests=600,expire=60):return'200 OK'exceptTooManyRequests:return'429 Too Many Requests'

示例:每小时100个请求

fromredis_rate_limitimportRateLimit,TooManyRequeststry:withRateLimit(resource='users_list',client='192.168.0.10',max_requests=100,expire=3600):return'200 OK'exceptTooManyRequests:return'429 Too Many Requests'

示例:您还可以设置一个工厂,以便以后使用它

fromredis_rate_limitimportRateLimiter,TooManyRequestslimiter=RateLimiter(resource='users_list',max_requests=100,expire=3600)try:withlimiter.limit(client='192.168.0.10'):return'200 OK'exceptTooManyRequests:return'429 Too Many Requests'

示例:您还可以传递可选的redis池

importredisfromredis_rate_limitimportRateLimit,TooManyRequestsredis_pool=redis.ConnectionPool(host='127.0.0.1',port=6379,db=0)try:withRateLimit(resource='users_list',client='192.168.0.10',max_requests=10,redis_pool=redis_pool):return'200 OK'exceptTooManyRequests:return'429 Too Many Requests'

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java组织。springframework。豆。工厂UnsatisfiedPendencyException:创建名为“demoRestController”的bean时出错   java如何在2d数组中创建不同的列大小   java垃圾值更新为文本文件   Java掷硬币建议   带类的java Hashmap   java数据定义字符串到数组   java部分类的代码生成   同时托管php和Java   java无效的ASCII编码偏移量   googleapijavaclient的youtube帮助   基于用户组的文件存储java变量路径   java NiftyGui如何更改面板大小   java创建标题为空的文件   java为什么谷歌会使用CloudMessaging。当文档读取时,register是否始终返回不同的令牌?   获取LayoutInflater Android Java中对象的访问权限