v8

package
v0.0.0-...-b2e13bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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

func (p *PeriodFailureStore) GetRunValue(ctx context.Context, key string) ([]int64, error)

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

func (p *PeriodStore) GetRunValue(ctx context.Context, key string) ([]int64, error)

GetRunValue get run value Exist: false if key not exist. Count: current count TTL: not set expire time, t = -1

func (*PeriodStore) SetQuotaFull

func (p *PeriodStore) SetQuotaFull(ctx context.Context, key string, quota, expireSec int) error

SetQuotaFull set a permit over quota.

func (*PeriodStore) Take

func (p *PeriodStore) Take(ctx context.Context, key string, quota, expireSec int) (int64, error)

Take requests a permit with context, it returns the permit state.

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).

func (*TokenLimit) AllowN

func (t *TokenLimit) AllowN(now time.Time, n int) bool

AllowN reports whether n events may happen at time now. Use this method if you intend to drop / skip events that exceed the rate. Otherwise, use Reserve or Wait.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL