dekuan/dedid
Composer 安装命令:
composer require dekuan/dedid
包简介
An unique id generator for distributed database by DeKuan, Inc.
README 文档
README
An unique id generator for primary key of distributed database. This implementation of the algorithm was referenced by Twitter Snowflake, but in the last 12 bits you can not only use the random numbers, but also get a hash value by your specified string.
ALGORITHM
Bit structure
It's a 64 bits bigint.
0 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx x xxxxx xxxxx xxxx xxxxxxxx
Details
| Position | Length | Usage | Remark |
|---|---|---|---|
| 0 | 1 | Reserved | Always be 0 |
| 1~41 | 41 | Escaped Time (in millisecond) | 0~69 years |
| 42~46 | 5 | Number of data center | 0~31 |
| 47~51 | 5 | Number of data node in the data center | 0~31 |
| 52~63 | 12 | Random / Hash | 0~4095 |
Bit marks
Center
0 00000000 00000000 00000000 00000000 00000000 0 11111 00000 0000 00000000
00000000 00000000 00000000 00000000 00000000 00111110 00000000 00000000
00 00 00 00 00 3E 00 00
Node
0 00000000 00000000 00000000 00000000 00000000 0 00000 11111 0000 00000000
00000000 00000000 00000000 00000000 00000000 00000001 11110000 00000000
00 00 00 00 00 01 F0 00
Escaped Time
0 11111111 11111111 11111111 11111111 11111111 1 00000 00000 0000 00000000
01111111 11111111 11111111 11111111 11111111 11000000 00000000 00000000
7F FF FF FF FF C0 00 00
Random or Hash value
0 00000000 00000000 00000000 00000000 00000000 0 00000 00000 1111 11111111
00000000 00000000 00000000 00000000 00000000 00000000 00001111 11111111
00 00 00 00 00 00 0F FF
HOW TO USE
Create an new id normally
$cDId = CDId::getInstance();
$nCenter = 0;
$nNode = 1;
$arrD = [];
$nNewId = $cDId->createId( $nCenter, $nNode, null, $arrD );
echo "new id = " . $nNewId . "\r\n";
print_r( $arrD );
output
new id = 114654484990270790
Array
(
[center] => 0
[node] => 1
[time] => 27335759399
[rand] => 3398
)
Create an new id with crc32 hash value by a specified string
$cDId = CDId::getInstance();
$nCenter = 0;
$nNode = 15;
$sSrc = "dekuan";
$arrD = [];
$nNewId = $cDId->createId( $nCenter, $nNode, $sSrc, $arrD );
echo "new id = " . $nNewId . "\r\n";
print_r( $arrD );
output
new id = 114654631304370386
Array
(
[center] => 0
[node] => 1
[time] => 27335794283
[rand] => 2258
)
Parse an id for getting the details
$cDId = CDId::getInstance();
$arrId = $cDId->parseId( 114654631304370386 );
print_r( $arrId );
output
Array
(
[center] => 0
[node] => 1
[time] => 27335794283
[rand] => 2258
)
INSTALL
# composer require dekuan/dedid
For more information, please visit https://packagist.org/packages/dekuan/dedid
dekuan/dedid 适用场景与选型建议
dekuan/dedid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.39k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2017 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dekuan/dedid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dekuan/dedid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 11
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2017-08-03