https://github.com/imiphp/imi-snowflake
imi 框架的雪花算法生成组件
https://github.com/imiphp/imi-snowflake
Last synced: 9 months ago
JSON representation
imi 框架的雪花算法生成组件
- Host: GitHub
- URL: https://github.com/imiphp/imi-snowflake
- Owner: imiphp
- License: mit
- Created: 2020-04-20T07:37:36.000Z (about 6 years ago)
- Default Branch: 2.0
- Last Pushed: 2024-01-19T01:35:48.000Z (over 2 years ago)
- Last Synced: 2025-06-30T12:45:29.685Z (11 months ago)
- Language: PHP
- Homepage: https://imiphp.com
- Size: 178 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# imi-snowflake
[](https://packagist.org/packages/imiphp/imi-snowflake)
[](https://secure.php.net/)
[](https://github.com/swoole/swoole-src)
[](https://github.com/imiphp/imi-snowflake/blob/master/LICENSE)
## 介绍
imi 框架的雪花算法生成组件
> 本仓库仅用于浏览,不接受 issue 和 Pull Requests,请前往:
## Composer
本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 `composer.json` 中加入下面的内容:
```json
{
"require": {
"imiphp/imi-snowflake": "~2.0.0"
}
}
```
然后执行 `composer update` 安装。
## 使用
在项目 `config/config.php` 中配置:
```php
[
'components' => [
// 引入本组件
'snowflake' => 'Imi\Snowflake',
],
]
```
### 配置
配置 `@app.beans`:
```php
[
'Snowflake' => [
'list' => [
// 可定义多个配置名称
'testBasic' => [
// 'datacenterId' => null, // 数据中心ID,未空时为0
// 'workerId' => null, // 工作进程ID,为空时取当前进程ID
// 'startTimeStamp' => null, // 开始时间戳,单位:毫秒
// 'redisPool' => null, // Redis 连接池名称,为空取默认连接池
],
],
],
]
```
### 生成ID
```php
$id = \Imi\Snowflake\SnowflakeUtil::id('testBasic');
```
### 解析ID
```php
$array = \Imi\Snowflake\SnowflakeUtil::parseId('testBasic', $id);
var_dump($array);
```
处理结果格式:
```php
array(4) {
["timestamp"]=>
string(35) "10100100111111101010001000001110010"
["sequence"]=>
string(12) "000000000000"
["workerid"]=>
string(5) "00000"
["datacenter"]=>
string(5) "00000"
}
```
## 免费技术支持
QQ群:17916227 [](https://jq.qq.com/?_wv=1027&k=5wXf4Zq),如有问题会有人解答和修复。
## 运行环境
- [PHP](https://php.net/) >= 7.4
- [Composer](https://getcomposer.org/) >= 2.0
- [Swoole](https://www.swoole.com/) >= 4.1.0
## 版权信息
`imi-snowflake` 遵循 MIT 开源协议发布,并提供免费使用。
## 鸣谢
感谢 [godruoyi/php-snowflake](https://github.com/godruoyi/php-snowflake) 为 imi-snowflake 提供算法驱动!
## 捐赠

开源不求盈利,多少都是心意,生活不易,随缘随缘……