redis

package
v0.0.0-...-4309684 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*TokenLimit)

func WithCapacity

func WithCapacity(capacity int) Option

WithCapacity 设置令牌桶容量

func WithRate

func WithRate(rate int) Option

WithRate 设置令牌桶每秒放入token速率

type TokenLimit

type TokenLimit struct {
	// contains filtered or unexported fields
}

TokenLimit controls how frequently events are allowed to happen with in one second.

func NewTokenLimiter

func NewTokenLimiter(key string, opts ...Option) *TokenLimit

NewTokenLimiter returns a PeriodLimit object. opts can be used to customize the PeriodLimit.

func (*TokenLimit) AllowN

func (tl *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