调整雪花算法

This commit is contained in:
yubaolee
2021-03-29 23:35:02 +08:00
parent 31811e9d9c
commit a333234f0c
15 changed files with 417 additions and 193 deletions

View File

@@ -15,18 +15,25 @@ namespace OpenAuth.Repository.Core
{
return Id == 0;
}
static LongEntity()
{
//设置参数,程序初始化时执行一次
var options = new IdGeneratorOptions()
{
Method = 1,
WorkerId = 1
};
YitIdHelper.SetIdGenerator(options);
}
/// <summary>
/// 采用雪花算法计算Id
/// </summary>
public override void GenerateDefaultKeyVal()
{
// 全局初始化设置WorkerId默认最大2^16-1。初始化过程全局只需一次且必须最先设置
var options = new IdGeneratorOptions(){ WorkerId = 1};
IIdGenerator IdHelper = new YitIdGenerator(options);
// 初始化以后就可以在需要的地方调用方法生成ID。
Id = IdHelper.NewLong();
Id = YitIdHelper.NextId();
}
}
}