From 1b6e0867ae1f10a7d01ddf23bf4fed4d2bb3b192 Mon Sep 17 00:00:00 2001 From: Samantha Frank Date: Thu, 26 Sep 2024 11:19:53 -0400 Subject: [PATCH] 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. --- ratelimits/source_redis.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ratelimits/source_redis.go b/ratelimits/source_redis.go index 83f704628..c8db1c462 100644 --- a/ratelimits/source_redis.go +++ b/ratelimits/source_redis.go @@ -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 {