Strategy/token bucket - #122
Merged
ArnabChatterjee20k merged 8 commits intoAug 13, 2026
Merged
Conversation
Introduce the storage-agnostic TokenBucket adapter (mirrors SlidingWindow: count()/remaining()/limit()/time()) and RedisBase, which owns the atomic refill-and-consume Lua script, a read-only refill estimate and the eval()/delete() seams. Bucket state is a single Redis hash; ttl is derived from capacity/refillRate.
Concrete adapters implementing the eval()/delete() seams plus getLogs() (reads bucket hashes via hGetAll). Constructor takes (key, tokens, refillRate).
Shared Base suite covering burst/capacity, remaining, refill over time, reset, refill-rate guard and unlimited (tokens 0).
Greptile SummaryThe PR adds token-bucket rate limiting backed by Redis, Redis Cluster, pooled Redis connections, and a no-op adapter. The latest changes refresh token balances when calculating remaining capacity and fully enumerate cluster keys before globally sorting and paginating them.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the stale remaining-count path now performs a fresh refill-aware read, and cluster pagination now scans the complete candidate set before sorting and slicing. Important Files Changed
Reviews (4): Last reviewed commit: "Merge branch 'strategy/sliding-window' i..." | Re-trigger Greptile |
…ount Fractional refill made floor(capacity - balance) undercount consumed tokens by one (e.g. balance 1.00001 -> 1 consumed instead of 2). Floor the available balance first, then subtract from capacity so remaining() stays exact.
The bucket refills continuously, so caching the consumed count made remaining() report a stale quota once time elapsed after a check(). Drop the cache and compute a fresh estimate on every count(); check() now only needs the allow decision.
…logs Stopping each master's unordered scan at offset+limit and then sorting/slicing the partial candidate set returned a biased page and could omit keys in range. Scan all masters completely, then sort and slice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.