We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3b6d1cb commit 4eb7a5dCopy full SHA for 4eb7a5d
ratelimiter/limiter.go
@@ -86,14 +86,19 @@ func (rl *RateLimiter) Allow(key string) (Response, error) {
86
}, nil
87
}
88
89
- // Increment request count atomically
90
- count, err := rl.storage.IncrementRequests(key, time.Now())
+ // Get current count first
+ count, err := rl.storage.GetRequests(key)
91
if err != nil {
92
return Response{}, err
93
94
95
// Allow requests until MaxRequests is reached
96
if count < rl.opts.MaxRequests {
97
+ // Increment only if we're under the limit
98
+ count, err = rl.storage.IncrementRequests(key, time.Now())
99
+ if err != nil {
100
+ return Response{}, err
101
+ }
102
return Response{
103
Allowed: true,
104
RequestsLeft: rl.opts.MaxRequests - count,
0 commit comments