counter

package
v0.1.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCounterRateLimiter

func NewCounterRateLimiter(ctx context.Context, client redis.Cmdable, key string, duration time.Duration,
	throughput int,
	batchSize int, opts ...Option) (ratelimit.Limiter, error)

Types

type Counter

type Counter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter() *Counter

func (*Counter) Incr

func (c *Counter) Incr() int

type CounterLimiter

type CounterLimiter struct {
	ratelimit.BaseRateLimiter

	N int64

	/*
		If the traffic is too large, the limiter will request Redis frequently.
		To avoid this situation, the frequency of accessing Redis will be limited.
	*/
	AntiDDoS bool
	// contains filtered or unexported fields
}

func (*CounterLimiter) Take

func (r *CounterLimiter) Take(ctx context.Context) (bool, error)

func (*CounterLimiter) Wait

func (r *CounterLimiter) Wait(ctx context.Context) (err error)

wait until take a token or timeout

type Option

type Option func(*CounterLimiter)

func WithAntiDDos

func WithAntiDDos(antiDDoS bool) Option

just for test

Jump to

Keyboard shortcuts

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