feat: Add distributed Redis-based rate limiting with sliding window, token bucket, and multi-tier support

- Add RedisRateLimiter struct with client/prefix/limit/window fields for distributed rate limit tracking
- Add RateLimitResult struct with allowed/remaining/reset_time/total_limit/retry_after fields
- Add NewRedisRateLimiter constructor and Allow method with Lua script for atomic sliding window operations
- Add AllowTokenBucket method with token bucket algorithm using Redis HMSET for refill rate
This commit is contained in:
nutcas3
2026-04-23 03:00:33 +03:00
parent 5a3f08829f
commit 85926ee377
2 changed files with 408 additions and 0 deletions
+1
View File
@@ -4,6 +4,7 @@ go 1.26
require (
github.com/gin-gonic/gin v1.12.0
github.com/go-redis/redis/v8 v8.11.5
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/stretchr/testify v1.11.1
github.com/swaggo/files v1.0.1