Limiter controls how frequently events are allowed to happen.
rdbrediser
Allow is a shortcut for AllowN(ctx, key, limit, 1).
AllowAtMost reports whether at most n events may happen at time now.
It returns number of allowed events that is less than or equal to n.
AllowN reports whether n events may happen at time now.
func NewLimiter(rdb rediser) *Limiter
Allowed is the number of events that may happen at time now.
Limit is the limit that was used to obtain this result.
Remaining is the maximum number of requests that could be
permitted instantaneously for this key given the current
state. For example, if a rate limiter allows 10 requests per
second and has already received 6 requests for this key this
second, Remaining would be 4.
ResetAfter is the time until the RateLimiter returns to its
initial state for a given key. For example, if a rate limiter
manages requests per second and received one request 200ms ago,
Reset would return 800ms. You can also think of this as the time
until Limit and Remaining will be equal.
RetryAfter is the time until the next request will be permitted.
It should be -1 unless the rate limit has been exceeded.
func Limiter.Allow(ctx context.Context, key string, limit Limit) (*Result, error)
func Limiter.AllowAtMost(ctx context.Context, key string, limit Limit, n int) (*Result, error)
func Limiter.AllowN(ctx context.Context, key string, limit Limit, n int) (*Result, error)
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.