Documentation
¶
Overview ¶
Package ranker 排序器类型 ranker可以用于分布式排序操作 即多个worker分别计算更新一部分元素的权重,业务端则只负责读取结果
Index ¶
- Variables
- 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, reverse bool) ([]string, error)
- func (r *Ranker) GetElementByRank(ctx context.Context, rank int64, reverse bool) (string, error)
- func (r *Ranker) GetRank(ctx context.Context, element string, reverse bool) (int64, error)
- func (r *Ranker) GetWeight(ctx context.Context, elementkey string) (float64, error)
- func (r *Ranker) Head(ctx context.Context, count int64, reverse bool) ([]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, reverse bool) ([]string, error)
- func (r *Ranker) Len(ctx context.Context) (int64, error)
- func (r *Ranker) Range(ctx context.Context, reverse bool, scop ...int64) ([]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, reverse bool) ([]string, error)
- func (r *Ranker) Update(ctx context.Context, element *redis.Z) error
- func (r *Ranker) UpdateM(ctx context.Context, elements ...*redis.Z) error
Constants ¶
This section is empty.
Variables ¶
var ErrParamNMustBePositive = errors.New("参数n必须是大于0")
ErrParamNMustBePositive 参数n必须是大于0
var ErrRankerror = errors.New("排名不存在")
ErrRankerror 排名不存在
Functions ¶
This section is empty.
Types ¶
type Ranker ¶
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 ¶
First 获取排名前若干位的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 前几位 @params reverse bool 倒序排序
func (*Ranker) GetElementByRank ¶
GetElementByRank 获取指定排名的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params rank int64 第几名 @params reverse bool 倒序排序
func (*Ranker) GetRank ¶
GetRank 获取指定元素的排名,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params count int64 前几位 @params reverse bool 倒序排序
func (*Ranker) GetWeight ¶
GetWeight 查看元素的权重 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elementkey string 元素的key
func (*Ranker) Head ¶
Head first的别名 @params ctx context.Context 上下文信息,用于控制请求的结束 @params count int64 前几位 @params reverse bool 倒序排序
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 ¶
Last 获取排名后若干位的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 后几位 @params reverse bool 倒序排序
func (*Ranker) Range ¶
Range 获取排名范围内的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params reverse bool 倒序排序 @params scop ...int64 排序范围
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 ¶
Tail Last的别名 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 后几位 @params reverse bool 倒序排序