celllimiter

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package celllimiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAutoRefreshInterval

func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options]

WithAutoRefreshInterval 设置自动刷新过期时间的设置

func WithDefaultCountPerPeriod

func WithDefaultCountPerPeriod(countPerPeriod int64) optparams.Option[Options]

WithDefaultCountPerPeriod 设置时间间隔内的token消减数

func WithDefaultPeriod

func WithDefaultPeriod(period int64) optparams.Option[Options]

WithDefaultPeriod 设置token消减间隔时长,单位s

func WithKey

func WithKey(key string) optparams.Option[Options]

WithKey 中间件通用设置,指定使用的键,注意设置后namespace依然有效

func WithMaxSize

func WithMaxSize(maxsize int64) optparams.Option[Options]

WithMaxSize 设置最大水位,必须大于0

func WithMaxTTL

func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options]

WithMaxTTL 设置token消减间隔时长,单位s

func WithNamespace

func WithNamespace(ns ...string) optparams.Option[Options]

WithNamespace 中间件通用设置,指定锁的命名空间

func WithSpecifiedKey

func WithSpecifiedKey(key string) optparams.Option[Options]

WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效

func WithTaskCron

func WithTaskCron(taskCron *cron.Cron) optparams.Option[Options]

WithTaskCron 设置定时器

func WithWarningSize

func WithWarningSize(warningSize int64) optparams.Option[Options]

WithWarningSize 设置警戒水位,必须大于0

Types

type Limiter

type Limiter struct {
	*cellhelper.RedisCell
	*limiterhelper.LimiterABC
	// contains filtered or unexported fields
}

Limiter 分布式限制器

func New

func New(cli redis.UniversalClient, opts ...optparams.Option[Options]) (*Limiter, error)

New 构造令牌桶限流器

func (*Limiter) Flood

func (c *Limiter) Flood(ctx context.Context, value int64) (bool, error)

func (*Limiter) IsFull

func (c *Limiter) IsFull(ctx context.Context) (bool, error)

IsFull 观测水位是否已满

func (*Limiter) Reset

func (c *Limiter) Reset(ctx context.Context) error

func (*Limiter) WaterLevel

func (c *Limiter) WaterLevel(ctx context.Context) (int64, error)

type Options

type Options struct {
	LimiterOpts []optparams.Option[limiterhelper.Options]
	CellOpts    []optparams.Option[cellhelper.Options]
}

Jump to

Keyboard shortcuts

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