Documentation ¶
Index ¶
- type PeriodFailureStore
- func (p *PeriodFailureStore) Check(ctx context.Context, key string, quota, expireSec int, success bool) (int64, error)
- func (p *PeriodFailureStore) Del(ctx context.Context, key string) error
- func (p *PeriodFailureStore) GetRunValue(ctx context.Context, key string) ([]int64, error)
- func (p *PeriodFailureStore) SetQuotaFull(ctx context.Context, key string, quota, expireSec int) error
- type PeriodStore
- func (p *PeriodStore) Del(ctx context.Context, key string) error
- func (p *PeriodStore) GetRunValue(ctx context.Context, key string) ([]int64, error)
- func (p *PeriodStore) SetQuotaFull(ctx context.Context, key string, quota, expireSec int) error
- func (p *PeriodStore) Take(ctx context.Context, key string, quota, expireSec int) (int64, error)
- type TokenLimit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PeriodFailureStore ¶
type PeriodFailureStore struct {
// contains filtered or unexported fields
}
A PeriodFailureStore is used to limit requests when failure during a period of time.
func NewPeriodFailureStore ¶
func NewPeriodFailureStore(store *redis.Client) *PeriodFailureStore
NewPeriodFailureStore returns a PeriodFailureLimit with given parameters.
func (*PeriodFailureStore) Check ¶
func (p *PeriodFailureStore) Check(ctx context.Context, key string, quota, expireSec int, success bool) (int64, error)
Check requests a permit.
func (*PeriodFailureStore) Del ¶
func (p *PeriodFailureStore) Del(ctx context.Context, key string) error
Del delete a permit
func (*PeriodFailureStore) GetRunValue ¶
GetRunValue get run value Exist: false if key not exist. Count: current failure count TTL: not set expire time, t = -1
func (*PeriodFailureStore) SetQuotaFull ¶
func (p *PeriodFailureStore) SetQuotaFull(ctx context.Context, key string, quota, expireSec int) error
SetQuotaFull set a permit over quota.
type PeriodStore ¶
type PeriodStore struct {
// contains filtered or unexported fields
}
A PeriodStore is used to limit requests during a period of time.
func NewPeriodStore ¶
func NewPeriodStore(store *redis.Client) *PeriodStore
NewPeriodStore returns a PeriodLimit with given parameters.
func (*PeriodStore) Del ¶
func (p *PeriodStore) Del(ctx context.Context, key string) error
Del delete a permit
func (*PeriodStore) GetRunValue ¶
GetRunValue get run value Exist: false if key not exist. Count: current count TTL: not set expire time, t = -1
func (*PeriodStore) SetQuotaFull ¶
SetQuotaFull set a permit over quota.
type TokenLimit ¶
type TokenLimit struct {
// contains filtered or unexported fields
}
TokenLimit controls how frequently events are allowed to happen with in one second.
func NewTokenLimit ¶
func NewTokenLimit(rate, burst int, key string, store *redis.Client) *TokenLimit
NewTokenLimit returns a new TokenLimit that allows events up to rate and permits bursts of at most burst tokens.
func (*TokenLimit) Allow ¶
func (t *TokenLimit) Allow() bool
Allow is shorthand for AllowN(time.Now(), 1).