ranker

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ranker 排序器类型 ranker可以用于分布式排序操作 即多个worker分别计算更新一部分元素的权重,业务端则只负责读取结果

Index

Constants

This section is empty.

Variables

View Source
var ErrParamNMustBePositive = errors.New("参数n必须是大于0")

ErrParamNMustBePositive 参数n必须是大于0

View Source
var ErrRankerror = errors.New("排名不存在")

ErrRankerror 排名不存在

Functions

This section is empty.

Types

type Ranker

type Ranker struct {
	*clientkey.ClientKey
}

Ranker 排序工具

func New

func New(k *clientkey.ClientKey) *Ranker

New 新建一个排序器 @params k *key.Key redis客户端的键对象

func (*Ranker) Add

func (r *Ranker) Add(ctx context.Context, element *redis.Z) error

Add 增加一个新元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements *redis.Z 要添加的带权重的元素

func (*Ranker) AddM

func (r *Ranker) AddM(ctx context.Context, elements ...*redis.Z) error

AddM 增加若干个新元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...*redis.Z 要添加的带权重的元素

func (*Ranker) AddOrUpdate

func (r *Ranker) AddOrUpdate(ctx context.Context, element *redis.Z) error

AddOrUpdate 如果元素存在则更新元素权重,不存在则增加元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params element *redis.Z 要添加或更新的带权重的元素

func (*Ranker) AddOrUpdateM

func (r *Ranker) AddOrUpdateM(ctx context.Context, elements ...*redis.Z) error

AddOrUpdateM 如果元素存在则更新元素权重,不存在则增加元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...*redis.Z 要添加或更新的带权重的元素

func (*Ranker) First

func (r *Ranker) First(ctx context.Context, n int64, reverse bool) ([]string, error)

First 获取排名前若干位的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 前几位 @params reverse bool 倒序排序

func (*Ranker) GetElementByRank

func (r *Ranker) GetElementByRank(ctx context.Context, rank int64, reverse bool) (string, error)

GetElementByRank 获取指定排名的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params rank int64 第几名 @params reverse bool 倒序排序

func (*Ranker) GetRank

func (r *Ranker) GetRank(ctx context.Context, element string, reverse bool) (int64, error)

GetRank 获取指定元素的排名,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params count int64 前几位 @params reverse bool 倒序排序

func (*Ranker) GetWeight

func (r *Ranker) GetWeight(ctx context.Context, elementkey string) (float64, error)

GetWeight 查看元素的权重 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elementkey string 元素的key

func (*Ranker) Head

func (r *Ranker) Head(ctx context.Context, count int64, reverse bool) ([]string, error)

Head first的别名 @params ctx context.Context 上下文信息,用于控制请求的结束 @params count int64 前几位 @params reverse bool 倒序排序

func (*Ranker) IncrWeight

func (r *Ranker) IncrWeight(ctx context.Context, elementkey string) (float64, error)

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, reverse bool) ([]string, error)

Last 获取排名后若干位的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 后几位 @params reverse bool 倒序排序

func (*Ranker) Len

func (r *Ranker) Len(ctx context.Context) (int64, error)

Len 获取排名器的当前长度 @params ctx context.Context 上下文信息,用于控制请求的结束

func (*Ranker) Range

func (r *Ranker) Range(ctx context.Context, reverse bool, scop ...int64) ([]string, error)

Range 获取排名范围内的元素,reverse为True则为从大到小否则为从小到大 @params ctx context.Context 上下文信息,用于控制请求的结束 @params reverse bool 倒序排序 @params scop ...int64 排序范围

func (*Ranker) Remove

func (r *Ranker) Remove(ctx context.Context, element interface{}) error

Remove 删除元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params element interface{} 要删除的元素

func (*Ranker) RemoveM

func (r *Ranker) RemoveM(ctx context.Context, elements ...interface{}) error

RemoveM 删除元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...interface{} 要删除的元素

func (*Ranker) Reset

func (r *Ranker) Reset(ctx context.Context) error

Reset 重置排名器 @params ctx context.Context 上下文信息,用于控制请求的结束

func (*Ranker) Tail

func (r *Ranker) Tail(ctx context.Context, n int64, reverse bool) ([]string, error)

Tail Last的别名 @params ctx context.Context 上下文信息,用于控制请求的结束 @params n int64 后几位 @params reverse bool 倒序排序

func (*Ranker) Update

func (r *Ranker) Update(ctx context.Context, element *redis.Z) error

Update 更新一个元素 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements *redis.Z 要更新的带权重的元素

func (*Ranker) UpdateM

func (r *Ranker) UpdateM(ctx context.Context, elements ...*redis.Z) error

UpdateM 更新元素的权重 @params ctx context.Context 上下文信息,用于控制请求的结束 @params elements ...*redis.Z 要更新的带权重的元素

Jump to

Keyboard shortcuts

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