Permalink
Browse files

Fix redis quota expiration

  • Loading branch information...
1 parent d4337ce commit 00954f6e6d75fb3364cb64a6ff7cafdc916ac384 @fiorix committed Dec 11, 2015
Showing with 6 additions and 5 deletions.
  1. +1 −1 apiserver/cmd.go
  2. +5 −4 apiserver/ratelimit.go
View
@@ -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"
@@ -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))

0 comments on commit 00954f6

Please sign in to comment.