Documentation ¶
Index ¶
Constants ¶
View Source
const ( BitLenTime = 41 // 41位存时间戳,大约可用69年 BitLenWorker = 10 // 11位存机器id BitLenReserve = 2 // 2位预留,可用于业务编码 BitLenAbnormality = 2 // 2位用于时间回退等异常情况,运行时可恢复 BitLenSequence = 8 // 8位用户1毫秒内的递增值,意味着系统1s内并发在(2^8-1)*1000=255000 BitLenTotal = BitLenTime + BitLenWorker + BitLenReserve + BitLenAbnormality + BitLenSequence )
Variables ¶
View Source
var (
StartTime = time.Date(2019, 1, 25, 0, 0, 0, 0, time.UTC).UnixNano() / nano // 起始时间,更改可能会导致id重复
)
Functions ¶
Types ¶
type UniqueId ¶
type UniqueId struct {
// contains filtered or unexported fields
}
func NewUniqueId ¶
返回id生成器的实例 配置 WorkerId 机器id; ReserveId 预留的值,可以是业务编码
Click to show internal directories.
Click to hide internal directories.