Skip to content

Commit

Permalink
ratelimits: Set a TTL each time we store bucket data in Redis (#7720)
Browse files Browse the repository at this point in the history
Set the Redis TTL to TAT (theoretical arrival time) plus a 10-minute
buffer to account for possible clock skew.
  • Loading branch information
beautifulentropy authored Sep 26, 2024
1 parent 2e2bb94 commit 1b6e086
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()) + 10*time.Minute
pipeline.Set(ctx, bucketKey, tat.UTC().UnixNano(), ttl)
}
_, err := pipeline.Exec(ctx)
if err != nil {
Expand Down

0 comments on commit 1b6e086

Please sign in to comment.