feat: Improve refs garbage collection for redis Redis using TTL #983
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We had many issues with Redis growing in size due to garbage collection not covering all the corner cases. Scanning all the repositories is not sustainable, and thus, using the webhook system seemed much more sustainable. So, a while ago, I decided to improve garbage collection by making sure all refs had a TTL so they would eventually be garbage collected.
I initially didn't open a pull request since Redis 7.4 now supports the TTL index on HSet. When I implemented this feature, I thought it would soon be obsolete. However, all things considered, it might still be relevant, so here it is.
Essentially, for each type (Project, Ref, and Metrics), we add a key with a TTL. When running the garbage collection job, if this key is no longer present, we delete the related element from the HSET.