Skip to content

Commit

Permalink
Fix redis quota expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
fiorix committed Dec 11, 2015
1 parent d4337ce commit 00954f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apiserver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 5 additions & 4 deletions apiserver/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 00954f6

Please sign in to comment.