mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 01:58:01 +08:00
调整雪花算法
This commit is contained in:
@@ -11,14 +11,16 @@ namespace Infrastructure.Test
|
||||
public void Generate()
|
||||
{
|
||||
// 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置)
|
||||
var options = new IdGeneratorOptions(){ WorkerId = 1};
|
||||
IIdGenerator IdHelper = new YitIdGenerator(options);
|
||||
var options = new IdGeneratorOptions()
|
||||
{
|
||||
Method = 1,
|
||||
WorkerId = 1
|
||||
};
|
||||
|
||||
// 初始化以后,就可以在需要的地方调用方法生成ID。
|
||||
long val =IdHelper.NewLong();
|
||||
int val2 = (int)val;
|
||||
|
||||
Console.WriteLine($"val:{val}/int:{val2}");
|
||||
YitIdHelper.SetIdGenerator(options);
|
||||
long newId = YitIdHelper.NextId();
|
||||
Console.WriteLine("=====================================");
|
||||
Console.WriteLine("生成的 Id:" + newId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user