ratelimits: Set a TTL each time we store bucket data in Redis (#7720)

Set the Redis TTL to TAT (theoretical arrival time) plus a 10-minute
buffer to account for possible clock skew.
This commit is contained in:
Samantha Frank 2024-09-26 11:19:53 -04:00 committed by GitHub
parent 2e2bb944cc
commit 1b6e0867ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -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 {