From 00954f6e6d75fb3364cb64a6ff7cafdc916ac384 Mon Sep 17 00:00:00 2001 From: Alexandre Fiori Date: Fri, 11 Dec 2015 13:34:37 -0500 Subject: [PATCH] Fix redis quota expiration --- apiserver/cmd.go | 2 +- apiserver/ratelimit.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apiserver/cmd.go b/apiserver/cmd.go index 7e89f33..6190713 100644 --- a/apiserver/cmd.go +++ b/apiserver/cmd.go @@ -24,7 +24,7 @@ import ( ) // Version tag. -var Version = "3.0.9" +var Version = "3.0.10" var maxmindDB = "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz" diff --git a/apiserver/ratelimit.go b/apiserver/ratelimit.go index be7d8cc..af05bdc 100644 --- a/apiserver/ratelimit.go +++ b/apiserver/ratelimit.go @@ -74,14 +74,15 @@ func (rl *RateLimiter) do(w http.ResponseWriter, r *http.Request) (int, error) { if err != nil { return http.StatusServiceUnavailable, errRedisUnavailable } - var ttl = 0 - if nreq == 1 { + ttl, err := rl.Redis.TTL(k) + if err != nil { + return http.StatusServiceUnavailable, errRedisUnavailable + } + if ttl == -1 { if _, err = rl.Redis.Expire(k, rl.secInterval); err != nil { return http.StatusServiceUnavailable, errRedisUnavailable } ttl = rl.secInterval - } else if ttl, err = rl.Redis.TTL(k); err != nil { - return http.StatusServiceUnavailable, errRedisUnavailable } rem := rl.Max - nreq w.Header().Set("X-RateLimit-Limit", strconv.Itoa(rl.Max))