data

package
v0.0.0-...-28c23ed Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 23 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DEFAULT_ID_EPOCH = int64(1704067200000) // Defaults to: 2024-01-01T00:00:00Z
)

Variables

View Source
var (
	ErrIdEpochOutOfRange       = errors.New("the value of 'idEpoch' must be greater than 0")
	ErrClusterIdBitsOutOfRange = errors.New("the value of 'clusterIdBits' must be greater than 0")
	ErrWorkerIdBitsOutOfRange  = errors.New("the value of 'workerIdBits' must be greater than 0")
	ErrSequenceBitsOutOfRange  = errors.New("the value of 'sequenceBits' must be greater than 0")
	ErrClusterIdOutOfRange     = errors.New("the value of 'clusterId' out of range")
	ErrWorkerIdOutOfRange      = errors.New("the value of 'workerId' out of range")
	ErrTimeMilliBitsOutOfRange = errors.New("the sum of 'clusterIdBits', 'workerIdBits' and 'sequenceBits' must be less than 23")
)

Functions

func NewBunDB

NewBunDB creates a new bun.IDB instance with metrics, tracing and logging.

func NewRedisClient

NewRedisClient creates a new redis client with tracing and metrics.

func SetDefaultIdWorker

func SetDefaultIdWorker(w IdWorker)

SetDefaultIdWorker sets the default IdWorker instance.

func WithPaging

func WithPaging(p pagetoken) func(*bun.SelectQuery) *bun.SelectQuery

WithPaging is a bun.SelectQuery modifier that adds paging to the query.

Types

type IdWorker

type IdWorker interface {
	NextInt64() int64
	NextBytes() [8]byte
	NextHex() string
}

IdWorker is used to generate unique id.

func DefaultIdWorker

func DefaultIdWorker() IdWorker

DefaultIdWorker returns the default IdWorker instance.

func NewIdWorker

func NewIdWorker(cfg config.SnowflakeConfig, seq Seq) (IdWorker, error)

NewIdWorker creates a new IdWorker instance with the given config. If the workerSeqKey is not empty, the workerId will be generated from the Seq.

type Seq

type Seq interface {
	// Next returns the next value in the sequence.
	Next(key string, min int64, max int64) (int64, error)
}

Seq is a sequence generator.

func NewRedisSeq

func NewRedisSeq(rdb rueidis.Client) Seq

NewRedisSeq creates a new redis sequence generator.

Jump to

Keyboard shortcuts

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