SnowflakeGenerator

The Snowflake generator is a thread-safe generator of unique "snowflake" ids, which guarantees that ids it generates will always be unique and always increasing in value, provided that there are no two generators with the same node id at the same time.

Here's a simple example of how to generate ids:

auto gen = SnowflakeGenerator(1);
long id = gen.nextId;

For background info on this type of id, please see [Twitter's original blog post on the topic](https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake).

Constructors

this
this(long nodeId, long epoch)

Constructs the generator using a given node id and epoch offset.

this
this(long nodeId)

Constructs the generator using a default epoch offset.

Members

Aliases

SnowflakeIdInfo
alias SnowflakeIdInfo = Tuple!(long, "timestamp", long, "nodeId", long, "sequence")

An alias for a tuple containing the basic information of a snowflake id.

Functions

nextId
long nextId()

Generates a new unique id. Calls to this method are synchronized such that ids from this generator are generated sequentially.

parseId
SnowflakeIdInfo parseId(long id)

Parses a snowflake id into its constituent parts.

Static variables

DEFAULT_CUSTOM_EPOCH
long DEFAULT_CUSTOM_EPOCH;
Undocumented in source.
EPOCH_BITS
auto EPOCH_BITS;
Undocumented in source.
MAX_NODE_ID
long MAX_NODE_ID;
Undocumented in source.
MAX_SEQUENCE
long MAX_SEQUENCE;
Undocumented in source.
NODE_ID_BITS
auto NODE_ID_BITS;
Undocumented in source.
SEQUENCE_BITS
auto SEQUENCE_BITS;
Undocumented in source.
UNUSED_BITS
auto UNUSED_BITS;
Undocumented in source.

Meta

Authors

Andrew Lalis, andrewlalisofficial@gmail.com