pkg

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 7 Imported by: 0

README

业务公共模块

  • 重复检测
  • counter
  • id生成器

Documentation

Overview

Package pkg 计数器,可以用于业务的各种模型统计使用 场景:常用于重复策略,或者反作弊处理控制

Package pkg ID 分配器,主要使用redis进行分配

Package pkg 重复提交模型封装

Index

Constants

View Source
const (
	// PrefixCounter counter key
	PrefixCounter = "eagle:counter:%s"
	// DefaultStep default step key
	DefaultStep = 1
	// DefaultExpirationTime .
	DefaultExpirationTime = 600 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CRepeat

type CRepeat struct {
	// contains filtered or unexported fields
}

CRepeat define struct

func NewCRepeat

func NewCRepeat() *CRepeat

NewCRepeat create a check repeat

func (*CRepeat) Del

func (c *CRepeat) Del(userID int64, check string) int64

Del delete

func (*CRepeat) Get

func (c *CRepeat) Get(userID int64, check string) (interface{}, error)

Get get value

func (*CRepeat) Set

func (c *CRepeat) Set(userID int64, check string, value interface{}, expiration time.Duration) error

Set record a repeat value

func (*CRepeat) SetNX

func (c *CRepeat) SetNX(userID int64, check string, value interface{}, expiration time.Duration) (bool, error)

SetNX set

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter define struct

func NewCounter

func NewCounter() *Counter

NewCounter create a counter

func (*Counter) DelCounter

func (c *Counter) DelCounter(ctx context.Context, idStr string) int64

DelCounter del count

func (*Counter) GetCounter

func (c *Counter) GetCounter(ctx context.Context, idStr string) (int64, error)

GetCounter get total count

func (*Counter) GetKey

func (c *Counter) GetKey(key string) string

GetKey 获取key

func (*Counter) SetCounter

func (c *Counter) SetCounter(ctx context.Context, idStr string, expiration time.Duration) (int64, error)

SetCounter set counter

type IDAlloc

type IDAlloc struct {
	// contains filtered or unexported fields
}

IDAlloc define struct

func NewIDAlloc

func NewIDAlloc() *IDAlloc

NewIDAlloc create a id alloc

func (*IDAlloc) GetUserID

func (i *IDAlloc) GetUserID() (int64, error)

GetUserID generate user id from redis

Jump to

Keyboard shortcuts

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