smorken / sequence-generator
v1.3
2020-09-03 13:34 UTC
Requires
- php: >=7.3
- psr/simple-cache: ^1.0.1
Requires (Dev)
- illuminate/support: ^6.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
- smorken/docker: *
README
默认情况下,基于(F64工厂)生成一个64位整数
- 32位时间戳(默认纪元为2020-01-01 00:00:00)
- 基于客户端IP和可选提供的整数的24位半唯一标识符(这是基于部分哈希,因此不能保证唯一)
- 每个标识符每秒旋转8位序列(每个标识符每秒256个ID)
F48工厂
- 30位时间戳
- 12位标识符
- 6位序列(每个标识符每秒64个ID)
Composer
安装
$ composer require smorken/sequence-generator
Laravel
当包含在composer中时应该自动加载。如果没有,请将服务提供者添加到config/app.php
...
Smorken\SeqGen\ServiceProvider::class,
...
通过DI或从容器中检索获取实例
$factory = app(\Smorken\SeqGen\Contracts\Factory::class);
$id = $factory->create('127.0.0.1');
//or with optional secondary identifier
$id = $factory->create('127.0.0.1', 12345678);
独立
$cache = new PSR16CacheProvider();
$if = new \Smorken\SeqGen\Identifiers\Factory(new \Smorken\SeqGen\Identifiers\Ip(), new \Smorken\SeqGen\Identifiers\IntVal());
$s = new \Smorken\SeqGen\Sequence();
$t = new \Smorken\SeqGen\Timestamp('2020-01-01 00:00:00');
$factory = new \Smorken\SeqGen\Factories\F64($cache, $if, $s, $t);
$id = $factory->create('127.0.0.1');
//or with optional secondary identifier
$id = $factory->create('127.0.0.1', 12345678);