Documentation
¶
Overview ¶
Package bucket implements the token bucket algorithm backed by Redis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsumeAll ¶
ConsumeAll atomically checks and consumes one token from each bucket. All buckets are checked first; tokens are only consumed if ALL buckets have sufficient tokens.
Returns the index of the first bucket that rejected (0-based), or -1 if all allowed.
Types ¶
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
TokenBucket represents a single rate limit bucket backed by Redis.
func New ¶
func New(namespace, serverName, suffix string, maxTokens int32, refillPeriod time.Duration) *TokenBucket
New creates a TokenBucket. The Redis key is derived from namespace, server name, and suffix (e.g., "global" or "global:tool:search").
func (*TokenBucket) RetryAfter ¶
func (b *TokenBucket) RetryAfter() time.Duration
RetryAfter returns the minimum wait time for one token to become available.
Click to show internal directories.
Click to hide internal directories.