snowflake32

package
v0.0.0-...-a86be45 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Snowflake

type Snowflake struct {
	sync.Mutex // 锁
	// contains filtered or unexported fields
}

Snowflake 24小时内不会重复的雪花序号生成器 构成为: 0 | seconds 17 bit | datacenter 2 bit | worker 3 bit| sequence 9 bit 最大支持32个节点,单节点TPS不超过512,超过则会阻塞程序到下一秒再返回序号,仅能用于特殊场景 seconds占用17bits是因为一天86400秒占用17bits

func NewSnowflake

func NewSnowflake(d int32, w int32) *Snowflake

NewSnowflake d for datacenter-id, w for worker-id

func Parse

func Parse(seq int32) *Snowflake

func (*Snowflake) Datacenter

func (s *Snowflake) Datacenter() int32

func (*Snowflake) NextVal

func (s *Snowflake) NextVal() int32

func (*Snowflake) Seconds

func (s *Snowflake) Seconds() int32

func (*Snowflake) Sequence

func (s *Snowflake) Sequence() int32

func (*Snowflake) String

func (s *Snowflake) String() string

func (*Snowflake) Worker

func (s *Snowflake) Worker() int32

Jump to

Keyboard shortcuts

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