FlakeGenerator
Flake generator.
Generates 64-bit unique IDs.
Attributes:
| Name | Type | Description |
|---|---|---|
worker_id |
int
|
Worker identifier. |
layout |
int
|
Layout. |
timestamp_bits |
int
|
Timestamp bits. |
worker_bits |
int
|
Worker bits. |
sequence_bits |
int
|
Sequence bits. |
time_unit_ns |
int
|
Time unit in nanoseconds. |
epoch_ms |
int
|
Epoch in time units. |
worker_id
property
Worker identifier.
The identifier for the machine that generated the ID.
layout
property
Layout.
The order of the timestamp, worker identifier, and sequence number.
Can be one of: - LAYOUT_TWS: timestamp, worker_id, sequence - LAYOUT_TSW: timestamp, sequence, worker_id
timestamp_bits
property
Timestamp bits.
The number of bits used to store the timestamp.
worker_bits
property
Worker bits.
The number of bits used to store the worker identifier.
sequence_bits
property
Sequence bits.
The number of bits used to store the sequence number.
time_unit_ns
property
Time unit in nanoseconds.
The number of nanoseconds that defines one time unit.
epoch
property
Epoch.
The number of time units since the Unix epoch.
__init__(worker_id=DEFAULT_WORKER_ID, *, epoch_ms=DEFAULT_EPOCH_MS, timestamp_bits=DEFAULT_TIMESTAMP_BITS, worker_bits=DEFAULT_WORKER_BITS, sequence_bits=DEFAULT_SEQUENCE_BITS, time_unit_ns=DEFAULT_TIME_UNIT_NS, layout=DEFAULT_LAYOUT, clock_func=None)
Initialize the FlakeGenerator instance.
generate()
Generate a 64-bit unique ID.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A 64-bit unique ID. |