Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stuartcarnie/lua-snowflake
An implementation of Snowflake for Lua. Snowflake is an algorithm which supports ordered, distributed id generation
https://github.com/stuartcarnie/lua-snowflake
Last synced: 6 days ago
JSON representation
An implementation of Snowflake for Lua. Snowflake is an algorithm which supports ordered, distributed id generation
- Host: GitHub
- URL: https://github.com/stuartcarnie/lua-snowflake
- Owner: stuartcarnie
- License: mit
- Created: 2014-10-28T06:44:33.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-03T19:53:00.000Z (about 10 years ago)
- Last Synced: 2023-04-14T06:38:29.303Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 176 KB
- Stars: 19
- Watchers: 3
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
lua-snowflake
=============An implementation of [Snowflake](https://blog.twitter.com/2010/announcing-snowflake) for Lua. Snowflake is an algorithm
which supports ordered, distributed id generation.Installation
------------$ luarocks install snowflake
Usage
-----local sf = require "snowflake"
sf.init(0x01, 0x01)
local uuid = sf.next_id()`uuid` will be a 64-bit number represented as a string that is structured as follows:
6 6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
tttttttttttttttttttttttttttttttttttttttttdddddnnnnnssssssssssssswhere
* `s` is a 12-bit integer that increments when next_id() is called multiple times for the same millisecond
* `n` is a 5-bit integer representing the node within a given data center
* `d` is a 5-bit integer representing a unique data center or group of servers
* `t` is a 42-bit integer representing the current timestamp in milliseconds
* the number of milliseconds to have elapsed since 1413817200000 or 2014-10-20T15:00:00.000Z`sf.init(datacenter_id, node_id)` is used to initialize snowflake and set values for ddddd and nnnnn as follows:
* `datacenter_id` is an integer n, where 0 ≤ n ≤ 0x1f and specifies the `ddddd` portion of the id
* `node_id` is an integer n, where 0 ≤ n ≤ 0x1f and specifies the `nnnnn` portion of the id