.net開發還在使用guid嗎?下面幾種id生成器更加合適

天天向上518發表於2024-04-26
 <ItemGroup>
    <PackageReference Include="IdGen" Version="3.0.5" />
    <PackageReference Include="Nanoid" Version="3.0.0" />
    <PackageReference Include="Snowflake.Core" Version="2.0.0" />
  </ItemGroup>
public async Task<string> DoworkIDs()
    {
        // IdGenerator idgen = new IdGenerator();
        // long getid = idgen.CreateId();

        string nanoidStr = await NanoidDotNet.Nanoid.GenerateAsync();

        long getId3 = new IdGen.IdGenerator(3).CreateId();
        long getId10 = new IdGen.IdGenerator(10).CreateId();

        Snowflake.Core.IdWorker snowflake = new Snowflake.Core.IdWorker(1,2,8);
        long snowflakeId = snowflake.NextId();
  
        return await Task.FromResult($"==getId3=={getId3},=====getId10={getId10},=====nanoidStr={nanoidStr}===snowflakeId=={snowflakeId}");
    }

相關文章