>> pec 5
16023976762414081
This is a unique id (64-bit integer) generator that can be used to generate unique identifiers for objects and database fields.
It currently supports linux and macOs, and work is in progress to add support for windows.
- To maintain sanity in your distributed system.
- If you do not wish to use auto-incremented primary keys.
- To avoid issues when you shard your SQL databases.
- If you constantly move data and you would like your fields / objects to remain unique.
composer require pec/pec
TIMESTAMP ---------- 45 BITS
CUSTOM BITS ------- 9 BITS
SEQUENCE BITS ----- 10 BITS
Copy the file pec
and add it to your PATH, or you can refer to it using it's absolute path.
The default epoch is January 1st, 2022.
The only thing you need to pass is a customId. It could be any number between 0 and 511 (both inclusive).
Please once you use a customId to generate id's for a project, you must keep using that customId for that project.
Using a customId of 5
>> pec 5
16023976762414081
To use your own timestamp,
>> pec 5 1652991600000
16023976762414081
Now, to use it from a script, you can use the system
or exec
commands or whatever function your framework or language offers to run shell commands.
For instance in php,
<?php
$id = system("pec 5")
echo $id;
For now, only linux and macOS are supported. Support for windows will soon be added.
To contribute, contact the email below.
Twitter : @phrenotyper
Email : paul.contrib@gmail.com