idsegment

package
v0.3.53 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	StatusCodeNil            = -iota // 成功
	StatusCodeUnknown                // 未知错误
	StatusCodeHUninit                // 没有初始化
	StatusCodeOverflow               // 超出上限
	StatusCodeBadParam               // 参数错误
	StatusCodeCacheIdUpdated         // 缓存中的Id已经更新过
)
View Source
const LUASCRIPT_HINCR = `` /* 652-byte string literal not displayed */

LUASCRIPT_HINCR 带判断的自增脚本 -1则未知错误,-2则为没有初始化,-3则超出上限,否则返回`起始值|上一个值|最大值|当前值`。

View Source
const LUASCRIPT_HREPL = `` /* 594-byte string literal not displayed */

LUASCRIPT_HREPL 重新设置的上限与当前值 -1则未知错误,-2则为没有初始化,-4则参数错误,否则返回当前值。

Variables

This section is empty.

Functions

This section is empty.

Types

type ICache

type ICache interface {
	Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
	EvalSha(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
}

type IRepository

type IRepository interface {
	// BlockNextSegment 利用事务以及行锁阻塞执行,同时在执行中加入尝试生成函数,如果成功执行,则表示不需要生成,执行回滚
	BlockNextSegment(ctx context.Context, key string, step uint64, tryGenerate func() (*Segment, error)) (uint64, uint64, *Segment, error)
}

type IdRecord

type IdRecord struct {
	Key      string `json:"key" gorm:"column:key;type:varchar(32);primaryKey;comment:业务主键"`
	BizId    int64  `json:"bizId" gorm:"column:bizId;type:bigint;comment:游戏ID"` // game id
	Value    uint64 `json:"value" gorm:"column:value;type:bigint;default:0;comment:业务当前值"`
	CreateAt int64  `json:"createAt" gorm:"column:createAt;<-:create;autoCreateTime;comment:创建时间"` // 创建时间
	UpdateAt int64  `json:"updateAt" gorm:"column:updateAt;autoUpdateTime;comment:修改时间"`           // 修改时间
}

func (IdRecord) Database

func (s IdRecord) Database() string

func (IdRecord) DbSharding

func (s IdRecord) DbSharding(keys ...any) string

func (IdRecord) ID

func (s IdRecord) ID() any

func (IdRecord) TableName

func (p IdRecord) TableName() string

func (IdRecord) ToJson

func (s IdRecord) ToJson() string

func (IdRecord) ToRow

func (s IdRecord) ToRow() []string

type IdRecordCache

type IdRecordCache struct {
	Client *redis.Client
}

func (IdRecordCache) Eval

func (i IdRecordCache) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)

func (IdRecordCache) EvalSha

func (i IdRecordCache) EvalSha(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)

type IdRecordRepository

type IdRecordRepository struct {
	gormex.BaseRepository[IdRecord]
	Options []dependency.BaseOptionFunc
}

func (IdRecordRepository) BlockNextSegment

func (i IdRecordRepository) BlockNextSegment(ctx context.Context, key string, step uint64, tryGenerate func() (*Segment, error)) (uint64, uint64, *Segment, error)

func (IdRecordRepository) Init

func (i IdRecordRepository) Init()

type IdSegment

type IdSegment struct {
	Batch uint64
	Cache ICache
	Repo  IRepository
}

func (IdSegment) GenerateSegment

func (i IdSegment) GenerateSegment(ctx context.Context, key string, num uint64) (*Segment, error)

func (IdSegment) NewID

func (i IdSegment) NewID(ctx context.Context, key string) (uint64, error)

func (IdSegment) NewIDIterate

func (i IdSegment) NewIDIterate(ctx context.Context, iterate func(uint64), key string, opts ...dep.Option) error

func (IdSegment) NewIDX

func (i IdSegment) NewIDX(ctx context.Context, key string) uint64

func (IdSegment) NewSegment

func (i IdSegment) NewSegment(ctx context.Context, key string, opts ...dep.Option) (*Segment, *Segment, error)

func (IdSegment) ReplGenerate

func (i IdSegment) ReplGenerate(ctx context.Context, key string, num uint64, tryGenerate func() (*Segment, error)) (*Segment, error)

type Segment

type Segment struct {
	Code   StatusCode `json:"code" form:"code" url:"code"`
	Cursor uint64     `json:"cursor" form:"cursor" url:"cursor"`
	MaxId  uint64     `json:"max" form:"max" url:"max"`
	MinId  uint64     `json:"min" form:"min" url:"min"`
}

type StatusCode

type StatusCode int32

func (StatusCode) ToError

func (i StatusCode) ToError() error

Jump to

Keyboard shortcuts

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