ratelimit

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Limit   int // 每秒限制
	Burst   int // 最大令牌数
	MaxSize int // 最大缓存数量
	Expiry  int // 缓存过期时间 单位秒
}

type RateLimit

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

func (*RateLimit) Allow

func (r *RateLimit) Allow(key string) bool

Allow 瞬间检查是否允许(不阻塞,直接返回 false 拒绝)

func (*RateLimit) AllowSBurst

func (r *RateLimit) AllowSBurst(key string, burst int) bool

func (*RateLimit) Init

func (r *RateLimit) Init(ctx context.Context, config config2.IConfig) error

func (*RateLimit) Stats

func (r *RateLimit) Stats() stats.Stats

Stats o可选:获取缓存统计(命中率、驱逐数等)

func (*RateLimit) Wait

func (r *RateLimit) Wait(key string) error

Wait 阻塞等待直到允许通过(推荐用于严格限流)

Jump to

Keyboard shortcuts

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