Module: Philiprehberger::IdGen::Snowflake
- Defined in:
- lib/philiprehberger/id_gen/snowflake.rb
Defined Under Namespace
Classes: Generator
Constant Summary collapse
- CUSTOM_EPOCH =
2020-01-01 00:00:00 UTC in milliseconds
1_577_836_800_000- TIMESTAMP_BITS =
41- WORKER_ID_BITS =
10- SEQUENCE_BITS =
12- MAX_WORKER_ID =
(1 << WORKER_ID_BITS) - 1
- MAX_SEQUENCE =
(1 << SEQUENCE_BITS) - 1
- WORKER_ID_SHIFT =
SEQUENCE_BITS- TIMESTAMP_SHIFT =
WORKER_ID_BITS + SEQUENCE_BITS
Class Method Summary collapse
Class Method Details
.timestamp(id, epoch_ms: CUSTOM_EPOCH) ⇒ Object
63 64 65 66 |
# File 'lib/philiprehberger/id_gen/snowflake.rb', line 63 def (id, epoch_ms: CUSTOM_EPOCH) = (id >> TIMESTAMP_SHIFT) + epoch_ms Time.at( / 1000.0) end |