hypercount

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hypercount 面向对象的计数估计类型 HyperCount 用于粗略统计大量数据去重后的个数,一般用在日活计算

Index

Constants

This section is empty.

Variables

View Source
var Defaultopt = Options{
	MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{},
}

Defaultopt 默认的可选配置

Functions

func WithAutoRefreshInterval added in v2.0.1

func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options]

WithAutoRefreshInterval 设置自动刷新过期时间的设置

func WithKey added in v2.0.1

func WithKey(key string) optparams.Option[Options]

WithKey 中间件通用设置,指定使用的键,注意设置后namespace依然有效

func WithMaxTTL added in v2.0.1

func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options]

WithMaxTTL 设置token消减间隔时长,单位s

func WithNamespace added in v2.0.1

func WithNamespace(ns ...string) optparams.Option[Options]

WithNamespace 中间件通用设置,指定锁的命名空间

func WithSpecifiedKey added in v2.0.1

func WithSpecifiedKey(key string) optparams.Option[Options]

WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效

func WithTaskCron added in v2.0.1

func WithTaskCron(taskCron *cron.Cron) optparams.Option[Options]

WithTaskCron 设置定时器

Types

type HyperCount

type HyperCount struct {
	*middlewarehelper.MiddleWareAbc
	// contains filtered or unexported fields
}

HyperCount 估计计数对象

func New

func New(cli redis.UniversalClient, opts ...optparams.Option[Options]) (*HyperCount, error)

New 创建一个新的计数对象 @params k *key.Key redis客户端的键对象

func (*HyperCount) Add

func (c *HyperCount) Add(ctx context.Context, item interface{}) error

Add 添加数据 @params ctx context.Context 上下文信息,用于控制请求的结束 @params item interface{} 添加的数据

func (*HyperCount) AddM

func (c *HyperCount) AddM(ctx context.Context, items ...interface{}) error

AddM 添加数据 @params ctx context.Context 上下文信息,用于控制请求的结束 @params items ...interface{} 添加的数据

func (*HyperCount) Len

func (c *HyperCount) Len(ctx context.Context) (int64, error)

Len 检查HyperLogLog中不重复元素的个数 @params ctx context.Context 上下文信息,用于控制请求的结束

func (*HyperCount) Reset

func (c *HyperCount) Reset(ctx context.Context) error

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

func (*HyperCount) Union

func (c *HyperCount) Union(ctx context.Context, otherhc []*HyperCount, newkeyopts ...optparams.Option[Options]) (*HyperCount, error)

Union 对应set的求并集操作 @params ctx context.Context 上下文信息,用于控制请求的结束 @params targetbmkey *clientkey.ClientKey 目标key对象 @params otherhc []*HyperCount 与之做并操作的其他HyperCount对象

type HyperCounterInterface added in v2.0.1

type HyperCounterInterface interface {

	//AddM 添加数据
	//@params ctx context.Context 上下文信息,用于控制请求的结束
	//@params items ...interface{} 添加的数据
	AddM(ctx context.Context, items ...interface{}) error

	//Add 添加数据
	//@params ctx context.Context 上下文信息,用于控制请求的结束
	//@params item interface{} 添加的数据
	Add(ctx context.Context, item interface{}) error

	//Len 检查HyperLogLog中不重复元素的个数
	//@params ctx context.Context 上下文信息,用于控制请求的结束
	Len(ctx context.Context) (int64, error)

	//Reset 重置当前hypercount
	//@params ctx context.Context 上下文信息,用于控制请求的结束
	Reset(ctx context.Context) error

	//Union 对应set的求并集操作
	//@params ctx context.Context 上下文信息,用于控制请求的结束
	//@params otherhc []*HyperCount 与之做并操作的其他HyperCount对象
	//@params newkeyopts ...optparams.Option[Options] 用于构造新HyperCount对象的参数
	Union(ctx context.Context, otherhc []*HyperCount, newkeyopts ...optparams.Option[Options]) (*HyperCount, error)
}

HyperCounterInterface 估算计数器接口

type Options added in v2.0.1

type Options struct {
	MiddlewareOpts []optparams.Option[middlewarehelper.Options] //初始化Middleware的配置
}

Options broker的配置

Jump to

Keyboard shortcuts

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