This commit is contained in:
zuohuaijun 2024-12-25 14:53:03 +08:00
commit 889f56ade2
2 changed files with 10 additions and 9 deletions

View File

@ -19,6 +19,14 @@ public static class YitIdHelperExtension
public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options)
{
if (App.GetConfig<CacheOptions>("Cache", true).CacheType == CacheTypeEnum.Memory.ToString())
{
YitIdHelper.SetIdGenerator(options);
SnowFlakeSingle.WorkId = options.WorkerId;
Console.WriteLine($"###########当前应用WorkId:【{options.WorkerId}】###########");
return;
}
_options = options;
// 排除开发环境和Windows服务器

View File

@ -22,15 +22,8 @@ public static class SqlSugarSetup
{
// 注册雪花Id
var snowIdOpt = App.GetConfig<SnowIdOptions>("SnowId", true);
if (App.GetConfig<CacheOptions>("Cache", true).CacheType == CacheTypeEnum.Memory.ToString())
{
YitIdHelper.SetIdGenerator(snowIdOpt);
SnowFlakeSingle.WorkId = snowIdOpt.WorkerId;
}
else
{
services.AddYitIdHelper(snowIdOpt);
}
services.AddYitIdHelper(snowIdOpt);
StaticConfig.CustomSnowFlakeFunc = () =>
{