Skip to content

Commit

Permalink
ratelimits: Add TTLs for Redis source
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Sep 23, 2024
1 parent 990ad07 commit 556830e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ratelimits/source_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (r *RedisSource) BatchSet(ctx context.Context, buckets map[string]time.Time

pipeline := r.client.Pipeline()
for bucketKey, tat := range buckets {
pipeline.Set(ctx, bucketKey, tat.UTC().UnixNano(), 0)
// Set a TTL of TAT + 10 minutes to account for clock skew.
ttl := tat.UTC().Sub(r.clk.Now()) + time.Minute*10
pipeline.Set(ctx, bucketKey, tat.UTC().UnixNano(), ttl)
}
_, err := pipeline.Exec(ctx)
if err != nil {
Expand Down

0 comments on commit 556830e

Please sign in to comment.