Documentation
¶
Index ¶
- Variables
- type IdFace
- type IdGenerator
- func (this_ *IdGenerator) GetId(ctx context.Context, idType IdType) (int64, error)
- func (this_ *IdGenerator) GetIds(ctx context.Context, idType IdType, size int64) ([]int64, error)
- func (this_ *IdGenerator) SetStartIdForType(idType IdType, startId int64)
- func (this_ *IdGenerator) WithIdStorageSpan(span int64) *IdGenerator
- func (this_ *IdGenerator) WithStartId(startId int64) *IdGenerator
- type IdHandler
- type IdType
- type Unlocker
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultIdStorageSpan int64 = 500 DefaultStartId int64 = 10000 )
Functions ¶
This section is empty.
Types ¶
type IdFace ¶
type IdFace interface {
GetId(ctx context.Context, idType IdType) (int64, error)
GetIds(ctx context.Context, idType IdType, size int64) ([]int64, error)
}
var ( // IdWorker 全局的ID生成器 请在 程序初始化 时候赋值 IdWorker IdFace )
type IdGenerator ¶
type IdGenerator struct {
// contains filtered or unexported fields
}
func NewIdGenerator ¶
func NewIdGenerator(handler IdHandler) *IdGenerator
func (*IdGenerator) SetStartIdForType ¶
func (this_ *IdGenerator) SetStartIdForType(idType IdType, startId int64)
SetStartIdForType 为特定类型设置起始ID
func (*IdGenerator) WithIdStorageSpan ¶
func (this_ *IdGenerator) WithIdStorageSpan(span int64) *IdGenerator
WithIdStorageSpan 设置ID存储跨度
func (*IdGenerator) WithStartId ¶
func (this_ *IdGenerator) WithStartId(startId int64) *IdGenerator
WithStartId 设置默认起始ID
type IdHandler ¶
type IdHandler interface {
ShouldCheckAndPersist() bool
// Increment 增长,使用 redis 的 incr 指令实现原子操作
// 如果缓存不存在则返回的 id 为 0
Increment(ctx context.Context, idType IdType, size int64) (int64, error)
// CacheId 缓存 id,缓存中不存在则通过 QueryId 查询恢复
CacheId(ctx context.Context, idType IdType, id int64) error
// StorageQueryId 存储 查询 id,缓存中不存在时进行查询
StorageQueryId(ctx context.Context, idType IdType) (int64, error)
// StorageInsert 存储 新增 id
StorageInsert(ctx context.Context, idType IdType, id int64) error
// StorageUpdate 存储 更新 id
StorageUpdate(ctx context.Context, idType IdType, id int64) error
// RecoverLock id 恢复锁,通常在存储时使用
RecoverLock(ctx context.Context, idType IdType) (Unlocker, error)
// PersistLock id 入库落地锁,通常在存储时使用
PersistLock(ctx context.Context, idType IdType) (Unlocker, error)
}
Click to show internal directories.
Click to hide internal directories.