snowflake

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidWorkerID = errors.New("worker ID excess of quantity")

Functions

This section is empty.

Types

type Options

type Options struct {
	Epoch      int64 // 初始时间戳,毫秒
	WorkerBits uint8 // 每台机器(节点)的ID位数 10位最大可以有2^10=1024个节点
	NumberBits uint8 // 表示每个集群下的每个节点,1毫秒内可生成的id序号的二进制位数 即每毫秒可生成 2^12-1=4096个唯一ID
	// contains filtered or unexported fields
}

func DefaultOptions

func DefaultOptions() Options

默认worker参数

func NewOptions

func NewOptions(epoch int64, workerBits uint8, numberBits uint8) Options

创建worker参数

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

定义一个woker工作节点所需要的基本参数

func NewWorker

func NewWorker(workerId int64, options Options) (*Worker, error)

实例化一个工作节点

func (*Worker) GetId

func (w *Worker) GetId() int64

接下来我们开始生成id 生成方法一定要挂载在某个woker下,这样逻辑会比较清晰 指定某个节点生成id

Jump to

Keyboard shortcuts

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