Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemcachedServer ¶
type MemcachedServer struct {
// contains filtered or unexported fields
}
MemcachedServer implements memcached protocol. You can use get,gets to get IDs.
func NewMemcachedServer ¶
func NewMemcachedServer(ln net.Listener, snowFlake *SnowFlake) *MemcachedServer
NewMemcachedServer returns a new MemcachedServer.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
A Node struct holds the basic information needed for a snowflake generator node
func (*Node) Generate ¶
Generate creates and returns a unique snowflake ID To help guarantee uniqueness - Make sure your system is keeping accurate system time - Make sure you never have multiple nodes running with the same node ID
func (*Node) GenerateBatch ¶
GenerateBatch creates and returns a batch of unique snowflake ID To help guarantee uniqueness - Make sure your system is keeping accurate system time - Make sure you never have multiple nodes running with the same node ID
func (*Node) ParseServerID ¶
ParseServerID returns an int64 of the snowflake ID node number.
type SnowFlake ¶
type SnowFlake struct {
// contains filtered or unexported fields
}
SnowFlake twitter snowflake backend. It is based on https://github.com/bwmarrin/snowflake and - remove some unused methods - add GenerateBatch methods
**How it Works**. Each time you generate an ID, it works, like this.
A timestamp with millisecond precision is stored using 41 bits of the ID. Then the NodeID is added in subsequent bits. Then the Sequence Number is added, starting at 0 and incrementing for each ID generated in the same millisecond. If you generate enough IDs in the same millisecond that the sequence would roll over or overfill then the generate function will pause until the next millisecond.
+--------------------------------------------------------------------------+ | 1 Bit Unused | 41 Bit Timestamp | 10 Bit NodeID | 12 Bit Sequence ID | +--------------------------------------------------------------------------+
func NewSnowFlake ¶
NewSnowFlake created a new SnowFlake with given configs.