-
Run Redis Server (port: 6379)
-
Run main.go Configuration
- useMem(Bool): set if you dont use Redis
- ipLimit(Int): rate limit for certain IP
- duration(time.Duration): time for rate limiting, reset after timeout
-
Run client request
curl -I 127.0.0.1:8080/hello
curl -H "X-Forwarded-For: 1.2.5.4:8080" -I 127.0.0.1:8080/hello
go run main.go -duration 1s -ipLimit 2
Rate Limiting
1000 times in an hour for each IP address
response X-RateLimit-Remaining
(remains time to visit) and X-RateLimit-Reset
(time to reset)
- count client visiting counts
- add timeout for each IP address
- add get/remove test (mem)
- add get/remove test (Redis)
- add Redis Ring (test only)
- use
PXAT
ifalicebob/miniredis
is available for redis v6.2 - add
atomic
for mem
INCR
and EXPIRE
are useful
ref: https://redislabs.com/redis-best-practices/basic-rate-limiting/