File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,14 @@ class IdGenerator
1515{
1616
1717 const TIMESTAMP_SHITF = 16 ;
18- const SEED_SHITF = 12 ;
18+ const WORKER_SHITF = 12 ;
1919
20+ protected $ workerId ;
2021
21- public function __construct ()
22+
23+ public function __construct ($ workerId = 1 )
2224 {
25+ $ this ->workerId = $ workerId ;
2326 }
2427
2528 protected function timestamp ()
@@ -31,17 +34,17 @@ public function next()
3134 {
3235 $ timestamp = $ this ->timestamp ();
3336 return ($ timestamp << self ::TIMESTAMP_SHITF )
34- | ($ this ->getSeed () << self ::SEED_SHITF )
37+ | ($ this ->getWorkerId () << self ::SEED_SHITF )
3538 | $ this ->getCount ($ timestamp );
3639 }
3740
3841 /**
3942 * 4bit for seed, 可用于业务和环境区分
4043 * @return int
4144 */
42- public function getSeed ()
45+ public function getWorkerId ()
4346 {
44- return 1 ;
47+ return $ this -> workerId ;
4548 }
4649
4750 /**
Original file line number Diff line number Diff line change 11# distributeIdGenerator
2- 依赖 Illuminate\Support\Facades\Redis
2+ 分布式id生成器,用于分布式环境序列号,订单号生成等
3+ 依赖 Illuminate\Support\Facades\Redis
You can’t perform that action at this time.
0 commit comments