Documentation ¶
Overview ¶
middlewarehelper 用于规范中间件的模块 中间件指的是一些有特殊业务用途的模块, 这个子模块是整个redishelper的一个基本组件
Index ¶
- Variables
- func DoCmdWithTTL(pipe redis.Pipeliner, ctx context.Context, cmd, key string, exp time.Duration, ...) *redis.Cmd
- func Force() optparams.Option[ForceOpt]
- func RefreshTTL() optparams.Option[RefreshOpt]
- func RefreshTTLAtFirstTime() optparams.Option[RefreshOpt]
- func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options]
- func WithKey(key string) optparams.Option[Options]
- func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options]
- func WithNamespace(ns ...string) optparams.Option[Options]
- func WithSpecifiedKey(key string) optparams.Option[Options]
- func WithTTL(t time.Duration) optparams.Option[RefreshOpt]
- func WithTTLAtFirstTime(t time.Duration) optparams.Option[RefreshOpt]
- func WithTaskCron(taskCron *cron.Cron) optparams.Option[Options]
- type ForceOpt
- type MiddleWareAbc
- func (l *MiddleWareAbc) AutoRefresh() error
- func (l *MiddleWareAbc) Client() redis.UniversalClient
- func (l *MiddleWareAbc) Delete(ctx context.Context) error
- func (l *MiddleWareAbc) DoCmdWithTTL(ctx context.Context, cmd, key string, exp time.Duration, params ...interface{}) (interface{}, error)
- func (l *MiddleWareAbc) Exists(ctx context.Context) (bool, error)
- func (l *MiddleWareAbc) Key() string
- func (l *MiddleWareAbc) Logger() *log.Log
- func (l *MiddleWareAbc) MaxTTL() time.Duration
- func (l *MiddleWareAbc) MiddlewareType() string
- func (l *MiddleWareAbc) RefreshTTL(ctx context.Context) error
- func (l *MiddleWareAbc) StopAutoRefresh(opts ...optparams.Option[ForceOpt]) error
- func (l *MiddleWareAbc) TTL(ctx context.Context) (time.Duration, error)
- func (l *MiddleWareAbc) Type(ctx context.Context) (string, error)
- type MiddlewareInterface
- type Options
- type RefreshOpt
- type RefreshTTLType
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = Options{ Namespace: namespace.NameSpcae{"redishelper"}, }
var ErrAutoRefreshTaskHasBeenSet = errors.New("autoRefresh task has been set")
ErrAutoRefreshTaskHasBeenSet 已经启动了自动刷新任务
var ErrAutoRefreshTaskInterval = errors.New("autoRefresh task interval not set")
ErrAutoRefreshTaskInterval 未设置自动刷新任务的间隔
var ErrAutoRefreshTaskNotSetYet = errors.New("autoRefresh task not set yet")
ErrAutoRefreshTaskNotSetYet 自动刷新任务未启动
var ErrKeyNotExists = errors.New("key not exists")
ErrKeyNotExists key不存在
var ErrKeyNotSetExpire = errors.New("key not set expire")
ErrKeyNotSetExpire key没有设置过期
var ErrKeyNotSetMaxTLL = errors.New("key not set MaxTLL ")
ErrKeyNotSetMaxTLL key没有设置最大tll
Functions ¶
func DoCmdWithTTL ¶ added in v2.1.0
func RefreshTTLAtFirstTime ¶ added in v2.1.0
func RefreshTTLAtFirstTime() optparams.Option[RefreshOpt]
RefreshTTLAtFirstTime 设置使用MaxTTL在key第一次设置时设置过期
func WithAutoRefreshInterval ¶
WithAutoRefreshInterval 设置自动刷新过期时间的设置
func WithMaxTTL ¶
WithMaxTTL 设置token消减间隔时长,单位s
func WithNamespace ¶
WithNamespace 中间件通用设置,指定锁的命名空间
func WithSpecifiedKey ¶
WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithTTL ¶ added in v2.1.0
func WithTTL(t time.Duration) optparams.Option[RefreshOpt]
WithTTL 设置总是使用指定的ttl刷新key
func WithTTLAtFirstTime ¶ added in v2.1.0
func WithTTLAtFirstTime(t time.Duration) optparams.Option[RefreshOpt]
WithTTL 设置总是使用指定的ttl刷新key
func WithTaskCron ¶
WithTaskCron 设置定时器
Types ¶
type MiddleWareAbc ¶
type MiddleWareAbc struct {
// contains filtered or unexported fields
}
func (*MiddleWareAbc) AutoRefresh ¶
func (l *MiddleWareAbc) AutoRefresh() error
AutoRefresh 自动刷新key的过期时间
func (*MiddleWareAbc) Client ¶
func (l *MiddleWareAbc) Client() redis.UniversalClient
Client 获取redis客户端
func (*MiddleWareAbc) Delete ¶
func (l *MiddleWareAbc) Delete(ctx context.Context) error
Delete 删除key @params ctx context.Context 上下文信息,用于控制请求的结束
func (*MiddleWareAbc) DoCmdWithTTL ¶ added in v2.1.0
func (*MiddleWareAbc) Exists ¶
func (l *MiddleWareAbc) Exists(ctx context.Context) (bool, error)
Exists 查看key是否存在 @params ctx context.Context 上下文信息,用于控制请求的结束
func (*MiddleWareAbc) Logger ¶
func (l *MiddleWareAbc) Logger() *log.Log
func (*MiddleWareAbc) MiddlewareType ¶
func (l *MiddleWareAbc) MiddlewareType() string
MiddlewareType 查看中间件类型
func (*MiddleWareAbc) RefreshTTL ¶
func (l *MiddleWareAbc) RefreshTTL(ctx context.Context) error
RefreshTTL 刷新key的生存时间 @params ctx context.Context 上下文信息,用于控制请求的结束
func (*MiddleWareAbc) StopAutoRefresh ¶
func (l *MiddleWareAbc) StopAutoRefresh(opts ...optparams.Option[ForceOpt]) error
StopAutoRefresh 取消自动更新缓存 @params force bool 强制停下整个定时任务cron对象
type MiddlewareInterface ¶
type MiddlewareInterface interface { //Cli 获取中间件使用的redis客户端 Cli() redis.UniversalClient //Key 查看中间件使用的redis键 Key() string //MiddlewareType 查看中间件类型,有lock,limiter,cache,counter,set,disctinct_counter,producer,consumer MiddlewareType() string //Exists 查看key是否存在 //@params ctx context.Context 上下文信息,用于控制请求的结束 Exists(ctx context.Context) (bool, error) //Type 查看key的类型 //@params ctx context.Context 上下文信息,用于控制请求的结束 Type(ctx context.Context) (string, error) //MaxTTL 查看组件设置的最大过期时间 MaxTTL() time.Duration //Logger 获取中间件对象的专用log Logger() *log.Log //TTL 查看key的剩余时间 //@params ctx context.Context 上下文信息,用于控制请求的结束 TTL(ctx context.Context) (time.Duration, error) //写操作 //Delete 删除key //@params ctx context.Context 上下文信息,用于控制请求的结束 Delete(ctx context.Context) error //RefreshTTL 刷新key的生存时间 //@params ctx context.Context 上下文信息,用于控制请求的结束 RefreshTTL(ctx context.Context) error //AutoRefresh 自动刷新key的过期时间 AutoRefresh() error //StopAutoRefresh 取消自动更新缓存 //@params opts ...optparams.Option[ForceOpt] 使用参数Force()强制停下整个定时任务cron对象 StopAutoRefresh(opts ...optparams.Option[ForceOpt]) error //DoCmdWithTTL 单条命令改为pipeline执行后添加ttl //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params cmd []interface{} 待执行命令 //@params exp time.Duration ttl超时 //@returns interface{} 命令执行好后调用`.Result()`返回的值 DoCmdWithTTL(ctx context.Context, cmd []interface{}, exp time.Duration) (interface{}, error) }
MiddlewareInterface 一个对象满足该接口表示它是一个redis构造的中间件
type RefreshOpt ¶ added in v2.1.0
type RefreshOpt struct { RefreshTTL RefreshTTLType TTL time.Duration }
RefreshOpt 是否刷新ttl的配置项
type RefreshTTLType ¶ added in v2.1.0
type RefreshTTLType int8
const ( RefreshTTLType_NoRefresh RefreshTTLType = iota RefreshTTLType_FirstTimeRefresh RefreshTTLType_Refresh )