Documentation ¶
Index ¶
- func NewGcraLimiter(rdb Rediser, key string, r float64, period time.Duration, b int) ratelimit.Limiter
- func NewGcraLimiterLimit(rdb Rediser, key string, l ratelimit.Limit) ratelimit.Limiter
- func NewGcraLimiterLimitFn(rdb Rediser, key string, fn LimitFn) ratelimit.Limiter
- type GcraLimiter
- func (gl *GcraLimiter) Allow() bool
- func (gl *GcraLimiter) AllowCtx(ctx context.Context) bool
- func (gl *GcraLimiter) AllowE() (bool, error)
- func (gl *GcraLimiter) AllowECtx(ctx context.Context) (bool, error)
- func (gl *GcraLimiter) AllowN(ctx context.Context, n int) (res *Result, err error)
- func (gl *GcraLimiter) ReserveE() (time.Duration, bool, error)
- func (gl *GcraLimiter) ReserveECtx(ctx context.Context) (time.Duration, bool, error)
- func (gl *GcraLimiter) Reset(ctx context.Context) error
- func (gl *GcraLimiter) Wait(ctx context.Context) error
- type LimitFn
- type Rediser
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGcraLimiter ¶
func NewGcraLimiter(rdb Rediser, key string, r float64, period time.Duration, b int) ratelimit.Limiter
NewGcraLimiter returns a new Limiter.
func NewGcraLimiterLimit ¶
NewGcraLimiterLimit returns a new Limiter.
Types ¶
type GcraLimiter ¶
type GcraLimiter struct {
// contains filtered or unexported fields
}
func (*GcraLimiter) Allow ¶
func (gl *GcraLimiter) Allow() bool
func (*GcraLimiter) AllowE ¶
func (gl *GcraLimiter) AllowE() (bool, error)
func (*GcraLimiter) ReserveECtx ¶
type Rediser ¶
type Rediser interface { Eval(ctx context.Context, script string, keys []string, args ...interface{}) *redis.Cmd EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *redis.Cmd ScriptExists(ctx context.Context, hashes ...string) *redis.BoolSliceCmd ScriptLoad(ctx context.Context, script string) *redis.StringCmd Del(ctx context.Context, keys ...string) *redis.IntCmd }
type Result ¶
type Result struct { // Limit is the limit that was used to obtain this result. Limit ratelimit.Limit // Allowed is the number of events that may happen at time now. Allowed int // 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. Remaining int // RetryAfter is the time until the next request will be permitted. // It should be -1 unless the rate limit has been exceeded. RetryAfter time.Duration // 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. ResetAfter time.Duration }
Click to show internal directories.
Click to hide internal directories.