Skip to content

Laravel snowflake 使用Twitter的SnowFlake算法,分布式生成唯一id

Notifications You must be signed in to change notification settings

heyhip/laravel-snowflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

laravel-snowflake

Laravel snowflake 使用Twitter的SnowFlake算法,分布式生成唯一id

安装方法

composer require youthage/snowflake

配置方法

配置工作机器ID,如下

#工作机器ID, 0-1023
config目录下创建baseconfig.php

内容为
<?php


return [

    'SNOWFLAKE_WORK_ID' => 1

];

使用方法

<?php

namespace App\Http\Controllers;

use Snowflake;
class IndexController extends Controller
{
    public function index()
    {
        $id = Snowflake::nextId();
        echo $id;
    }
}

About

Laravel snowflake 使用Twitter的SnowFlake算法,分布式生成唯一id

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages