snowflake v0.1.0
Snowflake
Snowflake ID generator implementation in Crystal programming language, which is designed to generate unique, time-based identifiers using a 64-bit structure. These identifiers consist of a timestamp component, a machine or process ID, and a sequence number to ensure uniqueness within the same millisecond.
Installation
-
Add the dependency to your
shard.yml
:dependencies: snowflake: github: mamantoha/snowflake
-
Run
shards install
Usage
require "snowflake"
machine_id = 1_u64 # Assign a unique machine/process ID
generator = Snowflake.new(machine_id)
snowflake_id = generator.generate_id
puts snowflake_id
# To convert a Snowflake ID back to a UTC timestamp
utc_time = Snowflake.id_to_utc(snowflake_id)
puts utc_time
Contributing
- Fork it (https://github.com/mamantoha/snowflake/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Anton Maminov - creator and maintainer
Repository
snowflake
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- 17 days ago
- February 25, 2024
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 15:23:25 GMT
Languages