snowflake

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FailCallbackFunc node id 失效后的回调函数,一般用于更新健康检查重启 pod
	FailCallbackFunc = func() {}
	// RedisClient 默认使用 redis 进行分布式 node id 配置及心跳机制
	// 使用默认 NodeIdGeneratorFunc 和 HeartBeatFunc 时必须设置
	RedisClient redis.UniversalClient
	// NodeIdGeneratorFunc 允许自定义的分布式ID生成器
	NodeIdGeneratorFunc DistributeIdGenerator = defaultGenerateDistributedNodeId
	// HeartBeatFunc 允许自定义的保持占有 node id 的心跳函数
	HeartBeatFunc HeartBeatExecutor = defaultHeartBeat

	NodeKeyTemplate = "snowflake:node:id:%d"

	HeartbeatInterval = 5 * time.Second
	OccupiedInterval  = 40 * time.Second
	FailThreshold     = 20 * time.Second // 必须小于 OccupiedInterval

)
View Source
var (
	Epoch    int64 = 1577836800000 // 设置 Epoch 为 2020/1/1 8:00
	NodeBits uint8 = 8             // 256 nodes
	StepBits uint8 = 14            // 16384 per millisecond
)

Functions

This section is empty.

Types

type DistributeIdGenerator added in v0.0.5

type DistributeIdGenerator func(key string) (id uint8, err error)

func (DistributeIdGenerator) Produce added in v0.0.5

func (f DistributeIdGenerator) Produce(key string) (id uint8, err error)

type HeartBeatExecutor added in v0.0.5

type HeartBeatExecutor func(node *Node)

func (HeartBeatExecutor) HeartBeat added in v0.0.5

func (f HeartBeatExecutor) HeartBeat(node *Node)

type Node

type Node struct {
	NodeId     uint8
	Identifier string
	// contains filtered or unexported fields
}

func NewNode

func NewNode(identifier string) (node *Node, nodeId uint8, err error)

func (*Node) Generate

func (n *Node) Generate() (sf.ID, error)

Jump to

Keyboard shortcuts

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