Documentation
¶
Overview ¶
Package hypercount 面向对象的计数估计类型 HyperCount 用于粗略统计大量数据去重后的个数,一般用在日活计算
Index ¶
- Variables
- 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 HyperCount
- func (c *HyperCount) Add(ctx context.Context, item interface{}) error
- func (c *HyperCount) AddM(ctx context.Context, items ...interface{}) error
- func (c *HyperCount) Len(ctx context.Context) (int64, error)
- func (c *HyperCount) Reset(ctx context.Context) error
- func (c *HyperCount) Union(ctx context.Context, otherhc []*HyperCount, ...) (*HyperCount, error)
- type HyperCounterInterface
- type Options
Constants ¶
This section is empty.
Variables ¶
var Defaultopt = Options{ MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{}, }
Defaultopt 默认的可选配置
Functions ¶
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 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 估算计数器接口