Documentation ¶
Overview ¶
cellhelper redis扩展[redis-cell](https://github.com/brandur/redis-cell)帮助模块,用于返回令牌桶状态
cellhelper redis扩展[redis-cell](https://github.com/brandur/redis-cell)帮助模块,用于返回令牌桶状态
Index ¶
- Variables
- func RefreshTTL() optparams.Option[ClThrottleOpts]
- func RefreshTTLAtFirstTime() optparams.Option[ClThrottleOpts]
- func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options]
- func WithCountPerPeriod(countPerPeriod int64) optparams.Option[ClThrottleOpts]
- func WithDefaultCountPerPeriod(countPerPeriod int64) optparams.Option[Options]
- func WithDefaultMaxBurst(maxBurst int64) optparams.Option[Options]
- func WithDefaultPeriod(period int64) optparams.Option[Options]
- func WithKey(key string) optparams.Option[Options]
- func WithMaxBurst(maxBurst int64) optparams.Option[ClThrottleOpts]
- func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options]
- func WithMiddlewaretype(typename string) optparams.Option[Options]
- func WithNamespace(ns ...string) optparams.Option[Options]
- func WithPeriod(period int64) optparams.Option[ClThrottleOpts]
- func WithSpecifiedKey(key string) optparams.Option[Options]
- func WithTTL(t time.Duration) optparams.Option[ClThrottleOpts]
- func WithTTLAtFirstTime(t time.Duration) optparams.Option[ClThrottleOpts]
- func WithTaskCron(taskCron *cron.Cron) optparams.Option[Options]
- type ClThrottleInPipePlacehold
- type ClThrottleOpts
- type Options
- type RedisCell
- type RedisCellStatus
Constants ¶
This section is empty.
Variables ¶
var Defaultopt = Options{ Middlewaretype: "redis-ext-cell", MaxBurst: 99, CountPerPeriod: 30, Period: 60, MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{}, }
Functions ¶
func RefreshTTL ¶
func RefreshTTL() optparams.Option[ClThrottleOpts]
RefreshTTL 设置总是刷新,该参数对pipeline无效
func RefreshTTLAtFirstTime ¶
func RefreshTTLAtFirstTime() optparams.Option[ClThrottleOpts]
RefreshTTLAtFirstTime 设置使用MaxTTL在key第一次设置时设置过期,该参数对pipeline无效
func WithAutoRefreshInterval ¶
WithAutoRefreshInterval 设置自动刷新过期时间的设置
func WithCountPerPeriod ¶
func WithCountPerPeriod(countPerPeriod int64) optparams.Option[ClThrottleOpts]
WithCountPerPeriod 设置时间间隔内的token消减数
func WithDefaultCountPerPeriod ¶
WithDefaultCountPerPeriod 设置时间间隔内的token消减数
func WithDefaultMaxBurst ¶
WithDefaultMaxBurst 设置最大熔断数,最大token数为MaxBurst+1
func WithDefaultPeriod ¶
WithDefaultPeriod 设置token消减间隔时长,单位s
func WithMaxBurst ¶
func WithMaxBurst(maxBurst int64) optparams.Option[ClThrottleOpts]
WithMaxBurst 设置最大熔断数,最大token数为MaxBurst+1
func WithMaxTTL ¶
WithMaxTTL 设置token消减间隔时长,单位s
func WithMiddlewaretype ¶
WithMiddlewaretype 设置中间件类型
func WithNamespace ¶
WithNamespace 中间件通用设置,指定锁的命名空间
func WithPeriod ¶
func WithPeriod(period int64) optparams.Option[ClThrottleOpts]
WithPeriod 设置token消减间隔时长,单位s
func WithSpecifiedKey ¶
WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithTTL ¶
func WithTTL(t time.Duration) optparams.Option[ClThrottleOpts]
WithTTL 设置总是使用指定的ttl刷新key,该参数对pipeline无效
func WithTTLAtFirstTime ¶
func WithTTLAtFirstTime(t time.Duration) optparams.Option[ClThrottleOpts]
WithTTL 设置总是使用指定的ttl刷新key
func WithTaskCron ¶
WithTaskCron 设置定时器
Types ¶
type ClThrottleInPipePlacehold ¶
type ClThrottleInPipePlacehold struct {
Cmd *redis.Cmd
}
func ClThrottleInPipe ¶
func ClThrottleInPipe(pipe redis.Pipeliner, ctx context.Context, key string, count int64, opts ...optparams.Option[ClThrottleOpts]) *ClThrottleInPipePlacehold
ClThrottleInPipe 增加桶中token数并返回桶状态 @params count int64 增加的token数量 @params opts ...optparams.Option[ClThrottleOpts] 其他参数,注意默认MaxBurst: 99,CountPerPeriod: 30,Period: 60
func (*ClThrottleInPipePlacehold) Result ¶
func (r *ClThrottleInPipePlacehold) Result() (*RedisCellStatus, error)
type ClThrottleOpts ¶
type ClThrottleOpts struct { RefreshOpts []optparams.Option[middlewarehelper.RefreshOpt] MaxBurst int64 CountPerPeriod int64 Period int64 }
ClThrottleOpt ClThrottle的配置
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 (*RedisCell) ClThrottle ¶
func (c *RedisCell) ClThrottle(ctx context.Context, count int64, opts ...optparams.Option[ClThrottleOpts]) (*RedisCellStatus, error)
ClThrottle 增加桶中token数并返回桶状态 @params count int64 增加的token数量 @params opts ...optparams.Option[ClThrottleOpts] 其他参数
Directories ¶
Path | Synopsis |
---|---|
Package celllimiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等
|
Package celllimiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等 |