Documentation
¶
Overview ¶
Package ranker 排序器类型 ranker可以用于分布式排序操作 即多个worker分别计算更新一部分元素的权重,业务端则只负责读取结果
Index ¶
- Variables
- func Reverse() optparams.Option[Rangescopopts]
- func ScopFrom(from int64) optparams.Option[Rangescopopts]
- func ScopTo(to int64) optparams.Option[Rangescopopts]
- 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 WithTaskCron(taskCron *cron.Cron) optparams.Option[Options]
- type Options
- type Rangescopopts
- type Ranker
- func (r *Ranker) Add(ctx context.Context, element *redis.Z) error
- func (r *Ranker) AddM(ctx context.Context, elements ...*redis.Z) error
- func (r *Ranker) AddOrUpdate(ctx context.Context, element *redis.Z) error
- func (r *Ranker) AddOrUpdateM(ctx context.Context, elements ...*redis.Z) error
- func (r *Ranker) First(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
- func (r *Ranker) GetElementByRank(ctx context.Context, rank int64, opts ...optparams.Option[Rangescopopts]) (string, error)
- func (r *Ranker) GetRank(ctx context.Context, element string, opts ...optparams.Option[Rangescopopts]) (int64, error)
- func (r *Ranker) GetWeight(ctx context.Context, elementkey string) (float64, error)
- func (r *Ranker) Head(ctx context.Context, count int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
- func (r *Ranker) IncrWeight(ctx context.Context, elementkey string) (float64, error)
- func (r *Ranker) IncrWeightM(ctx context.Context, elementkey string, weight float64) (float64, error)
- func (r *Ranker) Last(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
- func (r *Ranker) Len(ctx context.Context) (int64, error)
- func (r *Ranker) Range(ctx context.Context, opts ...optparams.Option[Rangescopopts]) ([]string, error)
- func (r *Ranker) Remove(ctx context.Context, element interface{}) error
- func (r *Ranker) RemoveM(ctx context.Context, elements ...interface{}) error
- func (r *Ranker) Reset(ctx context.Context) error
- func (r *Ranker) Tail(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
- func (r *Ranker) Update(ctx context.Context, element *redis.Z) error
- func (r *Ranker) UpdateM(ctx context.Context, elements ...*redis.Z) error
- type RankerInterface
Constants ¶
This section is empty.
Variables ¶
var Defaultopt = Options{ MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{}, }
Defaultopt 默认的可选配置
var ErrElementNotExist = errors.New("element not exist")
ErrElementNotExist 元素不存在
var ErrKeyNotExists = errors.New("key not exists")
ErrKeyNotExists key不存在
var ErrParamNMustBePositive = errors.New("param n must positive")
ErrParamNMustBePositive 参数n必须是大于0
var ErrRankerror = errors.New("ranker ror")
ErrRankerror 排名不存在
Functions ¶
func ScopFrom ¶ added in v2.0.1
func ScopFrom(from int64) optparams.Option[Rangescopopts]
ScopFrom 排序的下限
func WithAutoRefreshInterval ¶ added in v2.0.1
WithAutoRefreshInterval 设置自动刷新过期时间的设置
func WithMaxTTL ¶ added in v2.0.1
WithMaxTTL 设置token消减间隔时长,单位s
func WithNamespace ¶ added in v2.0.1
WithNamespace 中间件通用设置,指定锁的命名空间
func WithSpecifiedKey ¶ added in v2.0.1
WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithTaskCron ¶ added in v2.0.1
WithTaskCron 设置定时器
Types ¶
type Options ¶ added in v2.0.1
type Options struct {
MiddlewareOpts []optparams.Option[middlewarehelper.Options] //初始化Middleware的配置
}
Options broker的配置
type Rangescopopts ¶ added in v2.0.1
type Ranker ¶
type Ranker struct { *middlewarehelper.MiddleWareAbc // contains filtered or unexported fields }
Ranker 排序工具
func (*Ranker) Add ¶
Add 增加一个新元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements *redis.Z 要添加的带权重的元素
func (*Ranker) AddM ¶
AddM 增加若干个新元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...*redis.Z 要添加的带权重的元素
func (*Ranker) AddOrUpdate ¶
AddOrUpdate 如果元素存在则更新元素权重,不存在则增加元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params element *redis.Z 要添加或更新的带权重的元素
func (*Ranker) AddOrUpdateM ¶
AddOrUpdateM 如果元素存在则更新元素权重,不存在则增加元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...*redis.Z 要添加或更新的带权重的元素
func (*Ranker) First ¶
func (r *Ranker) First(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
First 获取排名前若干位的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 前几位 @params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效
func (*Ranker) GetElementByRank ¶
func (r *Ranker) GetElementByRank(ctx context.Context, rank int64, opts ...optparams.Option[Rangescopopts]) (string, error)
GetElementByRank 获取指定排名的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params rank int64 第几名 @params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效
func (*Ranker) GetRank ¶
func (r *Ranker) GetRank(ctx context.Context, element string, opts ...optparams.Option[Rangescopopts]) (int64, error)
GetRank 获取指定元素的排名,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params count int64 前几位 @params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效
func (*Ranker) GetWeight ¶
GetWeight 查看元素的权重 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elementkey string 元素的key
func (*Ranker) Head ¶
func (r *Ranker) Head(ctx context.Context, count int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
Head first的别名 @params ctx context.Context 上下文信息,用于控制请求的结束 @params count int64 前几位 @params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效
func (*Ranker) IncrWeight ¶
IncrWeight 为元素累增1的权重, @params ctx context.Context 上下文信息,用于控制请求的结束 @params elementkey string 元素的key
func (*Ranker) IncrWeightM ¶
func (r *Ranker) IncrWeightM(ctx context.Context, elementkey string, weight float64) (float64, error)
IncrWeightM 为元素累增一定数值的权重 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elementkey string 元素的key @params weight float64 元素的权重
func (*Ranker) Last ¶
func (r *Ranker) Last(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
Last 获取排名后若干位的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 后几位 @params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效
func (*Ranker) Range ¶
func (r *Ranker) Range(ctx context.Context, opts ...optparams.Option[Rangescopopts]) ([]string, error)
Range 获取排名范围内的元素,默认全量从小到大排序. @params ctx context.Context 上下文信息,用于控制请求的结束 @params opts ...optparams.Option[Rangescopopts]
func (*Ranker) Remove ¶
Remove 删除元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params element interface{} 要删除的元素
func (*Ranker) RemoveM ¶
RemoveM 删除元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...interface{} 要删除的元素
func (*Ranker) Tail ¶
func (r *Ranker) Tail(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error)
Tail Last的别名 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 后几位 @params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效
type RankerInterface ¶ added in v2.0.1
type RankerInterface interface { //AddM 增加若干个新元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elements ...*redis.Z 要添加的带权重的元素 AddM(ctx context.Context, elements ...*redis.Z) error //Add 增加一个新元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elements *redis.Z 要添加的带权重的元素 Add(ctx context.Context, element *redis.Z) error //UpdateM 更新元素的权重 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elements ...*redis.Z 要更新的带权重的元素 UpdateM(ctx context.Context, elements ...*redis.Z) error //Update 更新一个元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elements *redis.Z 要更新的带权重的元素 Update(ctx context.Context, element *redis.Z) error //AddOrUpdateM 如果元素存在则更新元素权重,不存在则增加元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elements ...*redis.Z 要添加或更新的带权重的元素 AddOrUpdateM(ctx context.Context, elements ...*redis.Z) error //AddOrUpdate 如果元素存在则更新元素权重,不存在则增加元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params element *redis.Z 要添加或更新的带权重的元素 AddOrUpdate(ctx context.Context, element *redis.Z) error //Reset 重置排名器 //@params ctx context.Context 上下文信息,用于控制请求的结束 Reset(ctx context.Context) error //IncrWeightM 为元素累增一定数值的权重 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elementkey string 元素的key //@params weight float64 元素的权重 IncrWeightM(ctx context.Context, elementkey string, weight float64) (float64, error) //IncrWeight 为元素累增1的权重, //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elementkey string 元素的key IncrWeight(ctx context.Context, elementkey string) (float64, error) //GetWeight 查看元素的权重 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elementkey string 元素的key GetWeight(ctx context.Context, elementkey string) (float64, error) //RemoveM 删除元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params elements ...interface{} 要删除的元素 RemoveM(ctx context.Context, elements ...interface{}) error //Remove 删除元素 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params element interface{} 要删除的元素 Remove(ctx context.Context, element interface{}) error // Len 获取排名器的当前长度 //@params ctx context.Context 上下文信息,用于控制请求的结束 Len(ctx context.Context) (int64, error) //Range 获取排名范围内的元素,默认全量从小到大排序. //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params opts ...optparams.Option[Rangescopopts] Range(ctx context.Context, opts ...optparams.Option[Rangescopopts]) ([]string, error) //First 获取排名前若干位的元素,reverse为True则为从大到小否则为从小到大 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params n int64 前几位 //@params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效 First(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error) //Head first的别名 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params count int64 前几位 //@params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效 Head(ctx context.Context, count int64, opts ...optparams.Option[Rangescopopts]) ([]string, error) //Last 获取排名后若干位的元素,reverse为True则为从大到小否则为从小到大 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params n int64 后几位 //@params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效 Last(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error) //Tail Last的别名 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params n int64 后几位 //@params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效 Tail(ctx context.Context, n int64, opts ...optparams.Option[Rangescopopts]) ([]string, error) //GetRank 获取指定元素的排名,reverse为True则为从大到小否则为从小到大 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params count int64 前几位 //@params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效 GetRank(ctx context.Context, element string, opts ...optparams.Option[Rangescopopts]) (int64, error) //GetElementByRank 获取指定排名的元素,reverse为True则为从大到小否则为从小到大 //@params ctx context.Context 上下文信息,用于控制请求的结束 //@params rank int64 第几名 //@params opts ...optparams.Option[Rangescopopts] 只有Reverse()会生效 GetElementByRank(ctx context.Context, rank int64, opts ...optparams.Option[Rangescopopts]) (string, error) }