module Sonyflake

Overview

A Crystal port of sony/sonyflake

require "sonyflake"
settings = Sonyflake::Settings.new(start_time: Time.utc(2020, 1, 1), machine_id: 1)

sonyflake = Sonyflake.new_sonyflake(settings)
puts sonyflake.next_id # => 302603879411875841
puts Sonyflake.get_instance.next_id # => 302603879411941377

Defined in:

Constant Summary

BIT_LEN_MACHINE_ID = (63 - BIT_LEN_TIME) - BIT_LEN_SEQUENCE
BIT_LEN_SEQUENCE = 8
BIT_LEN_TIME = 39
VERSION = "0.1.0"

Constructors

Constructor Detail

def self.get_instance : Sonyflake #

Get previously created instance

sonyflake = Sonyflake.get_instance

def self.new_sonyflake(settings : Settings) : Sonyflake? #

Generate a new sonyflake from the settings

require "sonyflake"
settings = Sonyflake::Settings.new(start_time: Time.utc(2020, 1, 1), machine_id: 1_u16)
sonyflake = Sonyflake.new_sonyflake(settings)