【优化】将系统常见多种编号生成方式修改为雪花漂移算法。

This commit is contained in:
大灰灰
2022-05-27 00:50:21 +08:00
parent 1e5816415d
commit 5e27be3e6d
4 changed files with 30 additions and 12 deletions

View File

@@ -140,14 +140,18 @@ namespace CoreCms.Net.Web.Admin
p.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});
// 雪花漂移算法
// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId
var options = new IdGeneratorOptions(1);
// WorkerIdBitLength 默认值6支持的 WorkerId 最大值为2^6-1若 WorkerId 超过64可设置更大的 WorkerIdBitLength
// options.WorkerIdBitLength = 10;
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
// 保存参数(必须的操作,否则以上设置都不能生效):
YitIdHelper.SetIdGenerator(options);
// 初始化以后即可在任何需要生成ID的地方调用以下方法
//var newId = YitIdHelper.NextId();
}