cellhelper

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

cellhelper redis扩展[redis-cell](https://github.com/brandur/redis-cell)帮助模块,用于返回令牌桶状态

Index

Constants

This section is empty.

Variables

View Source
var Defaultopt = Options{
	Middlewaretype: "redis-cell",
	MaxBurst:       99,
	CountPerPeriod: 30,
	Period:         60,
	MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{},
}

Functions

func WithAutoRefreshInterval

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

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

func WithCountPerPeriod

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

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

func WithKey

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

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

func WithMaxBurst

func WithMaxBurst(maxBurst int64) optparams.Option[Options]

WithMaxBurst 设置最大熔断数,最大token数为MaxBurst+1

func WithMaxTTL

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

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

func WithMiddlewaretype

func WithMiddlewaretype(typename string) optparams.Option[Options]

WithMiddlewaretype 设置中间件类型

func WithNamespace

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

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

func WithPeriod

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

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

func WithSpecifiedKey

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

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

func WithTaskCron

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

WithTaskCron 设置定时器

Types

type Options

type Options struct {
	Middlewaretype string
	MaxBurst       int64
	CountPerPeriod int64
	Period         int64
	MiddlewareOpts []optparams.Option[middlewarehelper.Options] //初始化Middleware的配置
}

Options broker的配置

type RedisCell

type RedisCell struct {
	*middlewarehelper.MiddleWareAbc
	// contains filtered or unexported fields
}

RedisCell 令牌桶对象

func New

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

New 创建一个新的令牌桶对象 @params cli redis.UniversalClient

func (*RedisCell) ClThrottle

func (c *RedisCell) ClThrottle(ctx context.Context, count int64) (*RedisCellStatus, error)

ClThrottle 增加桶中token数并返回桶状态 @params count int64 增加的token数量

func (*RedisCell) Clean

func (c *RedisCell) Clean(ctx context.Context) error

Clean 清除cell的key

type RedisCellStatus

type RedisCellStatus struct {
	Blocked          bool  `json:"blocked"`
	Max              int64 `json:"max"`
	Remaining        int64 `json:"remaining"`
	WaitForRetryTime int64 `json:"wait_for_retry_time"` //单位s,为-1表示不用等
	ResetToMaxTime   int64 `json:"reset_to_max_time"`   //单位s
}

RedisCellStatus 令牌桶的状态信息

Jump to

Keyboard shortcuts

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