2

I have been looking to enable the Rate Limiting feature with Eve, but have found very little documentation or examples on how to completely enabled it. I have added the RATE_LIMIT_GET and other configuration options for HTTP verbs and passed the redis parameter to the Eve() constructor. I am running redis locally as well on same server. Is there anything else that is needed? Any tips or suggestions would be greatly appreciated.

SamS
  • 61
  • 4

1 Answers1

1

My issue turned out to be that I was running within Docker and 'localhost' (the default value when instantiating Redis) does NOT resolve to the IP address of the container. Therefore, when I configured the Redis server in the run.py file I had to change the host name from 'localhost' to the IP address of the container. In the end I had Redis running in another container named 'redis' for other reasons, so I used that Redis instance in the code, but a separate DB:

redis_svr = redis.Redis(host='redis', db=1)
print('Redis server = ' + str(redis_svr), file=sys.stderr)
app = Eve(auth=BearerAuth, static_folder='templates', redis=redis_svr)

In the settings.py file I added these options and with the redis db working, rate limiting also worked:

#Rate Limit requests per 60 seconds
RATE_LIMIT_POST = (12, 60)
RATE_LIMIT_PATCH = (12, 60)
RATE_LIMIT_DELETE = (12, 60)
SamS
  • 61
  • 4