Documentation ¶
Index ¶
- Variables
- func CountItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, item string) (*redisbloomhelper.OneInt64MapPlacehold, error)
- func IncrItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, item string, ...) (*redisbloomhelper.StringListValPlacehold, error)
- func IncrWithIncrItems(incritems ...*redisbloomhelper.IncrItem) optparams.Option[IncrOpts]
- func IncrWithIncrement(n int64) optparams.Option[IncrOpts]
- func IncrWithItemMap(itemmap map[string]int64) optparams.Option[IncrOpts]
- func IncrWithItems(items ...string) optparams.Option[IncrOpts]
- func IncrWithRefreshTTL() optparams.Option[IncrOpts]
- func IncrWithTTL(t time.Duration) optparams.Option[IncrOpts]
- func InitPipe(pipe redis.Pipeliner, ctx context.Context, key string, topk int64, ...) *redis.Cmd
- func InitWithDecay(decay float64) optparams.Option[InitOpts]
- func InitWithDepth(depth int64) optparams.Option[InitOpts]
- func InitWithRefreshTTL() optparams.Option[InitOpts]
- func InitWithTTL(t time.Duration) optparams.Option[InitOpts]
- func InitWithWidth(width int64) optparams.Option[InitOpts]
- func ListPipe(pipe redis.Pipeliner, ctx context.Context, key string) *redisbloomhelper.StringListValPlacehold
- func MCountItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, items ...string) (*redisbloomhelper.Int64MapPlacehold, error)
- func MIncrItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, ...) (*redisbloomhelper.StringListValPlacehold, error)
- func MQueryItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, items ...string) (*redisbloomhelper.BoolMapPlacehold, error)
- func QueryItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, item string) (*redisbloomhelper.OneBoolMapPlacehold, error)
- func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options]
- func WithInit(topk int64, opts ...optparams.Option[InitOpts]) optparams.Option[Options]
- func WithKey(key string) optparams.Option[Options]
- func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options]
- func WithMiddlewaretype(typename string) 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 CountItem
- type CountItemPlacehold
- type IncrOpts
- type InfoPlacehold
- type InitOpts
- type Options
- type TopK
- func (c *TopK) Clean(ctx context.Context) error
- func (c *TopK) CountItem(ctx context.Context, item string) (int64, error)
- func (c *TopK) IncrItem(ctx context.Context, item string, opts ...optparams.Option[IncrOpts]) ([]string, error)
- func (c *TopK) Info(ctx context.Context) (*TopKInfo, error)
- func (c *TopK) Init(ctx context.Context, topk int64, opts ...optparams.Option[InitOpts]) error
- func (c *TopK) List(ctx context.Context) ([]string, error)
- func (c *TopK) ListWithCount(ctx context.Context) ([]*CountItem, error)
- func (c *TopK) MCountItem(ctx context.Context, items ...string) (map[string]int64, error)
- func (c *TopK) MIncrItem(ctx context.Context, opts ...optparams.Option[IncrOpts]) ([]string, error)
- func (c *TopK) MQueryItem(ctx context.Context, items ...string) (map[string]bool, error)
- func (c *TopK) QueryItem(ctx context.Context, item string) (bool, error)
- type TopKInfo
Constants ¶
This section is empty.
Variables ¶
var Defaultopt = Options{ Middlewaretype: "redis-ext-topk", MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{}, InitOpts: []optparams.Option[InitOpts]{}, }
Functions ¶
func CountItemPipe ¶
func CountItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, item string) (*redisbloomhelper.OneInt64MapPlacehold, error)
CountItemPipe topk中检查item的计数,注意这个计数永远不会高于实际数量并且可能会更低. @params key string 使用的key @params item string 要检查的物品 @return *redisbloomhelper.OneInt64MapPlacehold item对应的计数的占位符,使用`.Result()`获取值
func IncrItemPipe ¶
func IncrItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, item string, opts ...optparams.Option[IncrOpts]) (*redisbloomhelper.StringListValPlacehold, error)
IncrItemPipe 为物品添加计数 @params key string 使用的key @params item string 物品及其对应的增量 @returns *redisbloomhelper.StringListValPlacehold 新增后被挤出队列的物品的占位符,使用`.Result()`获取值
func IncrWithIncrItems ¶
func IncrWithIncrItems(incritems ...*redisbloomhelper.IncrItem) optparams.Option[IncrOpts]
IncrWithIncrItems MincrItem专用,使用IncrItems的列表设置items,使用该参数标明将执行incrby而非add,因此不能和IncrWithItems混用 注意增量小于1会被调整为1
func IncrWithIncrement ¶
IncrWithIncrement IncrItem专用,为物品设置增量
func IncrWithItemMap ¶
IncrWithItemMap MincrItem专用,使用字段形式设置items,使用该参数标明将执行incrby而非add,因此不能和IncrWithItems混用 注意增量小于1会被调整为1
func IncrWithItems ¶
IncrWithItems MincrItem专用,设置items并且不添加增量,使用该参数标明将执行add而非incrby,因此不能和IncrWithItemMap以及IncrWithIncrItems混用
func IncrWithRefreshTTL ¶
IncrWithhRefreshTTL 设置总是刷新
func IncrWithTTL ¶
IncrWithTTL 设置总是使用指定的ttl刷新key
func InitPipe ¶
func InitPipe(pipe redis.Pipeliner, ctx context.Context, key string, topk int64, opts ...optparams.Option[InitOpts]) *redis.Cmd
InitPipe 初始化TopK @params key string 使用的key @params topk int64 结构保存的topk @params opts ...optparams.Option[InitOpts] 可选参数
func InitWithDecay ¶
InitWithDecay 使用概率方式初始化
func InitWithDepth ¶
InitWithDepth 使用概率方式初始化
func InitWithRefreshTTL ¶
InitWithhRefreshTTL 设置使用maxttl设置key的过期,pipeline无效
func InitWithTTL ¶
InitWithTTL 设置使用指定的ttl设置key的过期
func InitWithWidth ¶
InitWithWidth 使用概率方式初始化
func ListPipe ¶
func ListPipe(pipe redis.Pipeliner, ctx context.Context, key string) *redisbloomhelper.StringListValPlacehold
ListPipe 列出全部topk物品 @params key string 使用的key
func MCountItemPipe ¶
func MCountItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, items ...string) (*redisbloomhelper.Int64MapPlacehold, error)
MCountItemPipe topk中检查item的计数,注意这个计数永远不会高于实际数量并且可能会更低. @params key string 使用的key @params items ...string 要检查的物品 @return *redisbloomhelper.Int64MapPlacehold item对应的计数的占位符,使用`.Result()`获取值
func MIncrItemPipe ¶
func MIncrItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, opts ...optparams.Option[IncrOpts]) (*redisbloomhelper.StringListValPlacehold, error)
MIncrItemPipe 为物品添加计数 @params key string 使用的key @params opts ...optparams.Option[IncrOpts] 请求设置项,请使用`IncrWithItems`或`IncrWithItemMap`或`IncrWithIncrItems`设置物品及其增量 @returns *redisbloomhelper.StringListValPlacehold 新增后被挤出队列的物品的占位符,使用`.Result()`获取值
func MQueryItemPipe ¶
func MQueryItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, items ...string) (*redisbloomhelper.BoolMapPlacehold, error)
MQueryItemPipe 查看物品当前是否在topk序列 @params key string 使用的key @params items ...string 待查看物品 @returns *redisbloomhelper.BoolMapPlacehold 物品:是否在topk序列的占位符,使用`.Result()`获取值
func QueryItemPipe ¶
func QueryItemPipe(pipe redis.Pipeliner, ctx context.Context, key string, item string) (*redisbloomhelper.OneBoolMapPlacehold, error)
QueryItemPipe 查看物品当前是否在topk序列 @params key string 使用的key @params item ...string 待查看物品 @returns *redisbloomhelper.OneBoolMapPlacehold 是否在topk序列(true为在)的占位符,使用`.Result()`获取值
func WithAutoRefreshInterval ¶
WithAutoRefreshInterval 设置自动刷新过期时间的设置
func WithMaxTTL ¶
WithMaxTTL 设置token消减间隔时长,单位s
func WithMiddlewaretype ¶
WithMiddlewaretype 设置中间件类型
func WithNamespace ¶
WithNamespace 中间件通用设置,指定锁的命名空间
func WithSpecifiedKey ¶
WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithTaskCron ¶
WithTaskCron 设置定时器
Types ¶
type CountItemPlacehold ¶
type CountItemPlacehold struct { Ck string Cmd *redis.Cmd }
func ListWithCountPipe ¶
func ListWithCountPipe(pipe redis.Pipeliner, ctx context.Context, key string) *CountItemPlacehold
ListWithCountPipe 列出全部topk物品及其对应的权重 @params key string 使用的key
func (*CountItemPlacehold) Result ¶
func (r *CountItemPlacehold) Result() ([]*CountItem, error)
type IncrOpts ¶
type IncrOpts struct { RefreshOpts []optparams.Option[middlewarehelper.RefreshOpt] Increment int64 //incr专用 MincrItems []string //mincr专用 MincrIncrement []int64 //mincr专用 }
type InfoPlacehold ¶
type InfoPlacehold struct { Ck string Cmd *redis.Cmd }
func InfoPipe ¶
func InfoPipe(pipe redis.Pipeliner, ctx context.Context, key string) *InfoPlacehold
InfoPipe 查看指定TopK的状态 @params key string 使用的key
func (*InfoPlacehold) Result ¶
func (r *InfoPlacehold) Result() (*TopKInfo, error)
type InitOpts ¶
type InitOpts struct { Width int64 Depth int64 Decay float64 RefreshOpts []optparams.Option[middlewarehelper.RefreshOpt] }
type Options ¶
type Options struct { Middlewaretype string MiddlewareOpts []optparams.Option[middlewarehelper.Options] //初始化Middleware的配置 InitTopK int64 InitOpts []optparams.Option[InitOpts] //初始化参数 }
Options broker的配置
type TopK ¶
type TopK struct { *middlewarehelper.MiddleWareAbc // contains filtered or unexported fields }
TopK TopK对象,用于统计大量数据下的前几位有哪些 比较常见的场景比如大量数据情况下的排行榜应用 使用了算法[HeavyKeeper](https://www.usenix.org/system/files/conference/atc18/atc18-gong.pdf). 其基本原理是使用一个shape为(width,depth)的表保存物品的签名和计数,通过hash函数将签名和计数更新进表,并同时使用指数衰减的方法淘汰小流量数据 取的时候取其中的最大值作为物品的计数 注意,和两个filter不同,cms必须先创建,incr不会创建cms结构,可以先创建再调用init方法初始化,也可以创建时使用对应的可选参数同步初始化
func New ¶
New 创建一个topk对象 @params cli redis.UniversalClient @params opts ...optparams.Option[Options]
func (*TopK) CountItem ¶
CountItem topk中检查item的计数,注意这个计数永远不会高于实际数量并且可能会更低. @params item string 要检查的物品 @return map[string]int64 item对应的计数
func (*TopK) IncrItem ¶
func (c *TopK) IncrItem(ctx context.Context, item string, opts ...optparams.Option[IncrOpts]) ([]string, error)
IncrItem 为物品添加计数 @params item string 物品及其对应的增量 @returns []string 新增后被挤出队列的物品
func (*TopK) Init ¶
Init 初始化TopK @params opts ...optparams.Option[InitOpts] 注意InitWithProbability和InitWithDIM必选一个,如果选了超过一个则会默认取第一个
func (*TopK) ListWithCount ¶
ListWithCount 列出全部topk物品及其对应的权重
func (*TopK) MCountItem ¶
MCountItem topk中检查item的计数,注意这个计数永远不会高于实际数量并且可能会更低. @params items ...string 要检查的物品 @return map[string]int64 item对应的计数
func (*TopK) MIncrItem ¶
MIncrItem 为物品添加计数 @params opts ...optparams.Option[IncrOpts] 请求设置项,请使用`IncrWithItems`或`IncrWithItemMap`或`IncrWithIncrItems`设置物品及其增量 @returns []string 新增后被挤出队列的物品
func (*TopK) MQueryItem ¶
MQueryItem 查看物品当前是否在topk序列 @params items ...string 待查看物品 @returns map[string]bool 物品:是否在topk序列