Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将实体主键改为雪花算法 #287

Closed
gmf520 opened this issue Nov 11, 2022 · 5 comments
Closed

将实体主键改为雪花算法 #287

gmf520 opened this issue Nov 11, 2022 · 5 comments
Labels
Feature 🔨 新功能,新特性 Finished ✔️ 实现并完工
Milestone

Comments

@gmf520
Copy link
Member

gmf520 commented Nov 11, 2022

您的功能请求与现有问题有关吗?请描述

  • 实体主键的数据类型,int自增不容易应对数据迁移,合并,分布式,分库分表等需求,Guid太长且复杂
  • long类型的雪花算法较短且有序,是最佳解决方案

描述您想要的需求方案

将实体主键类型更改为long类型,使用雪花算法给值,应用库:https://github.com/yitter/IdGenerator

@gmf520 gmf520 added the Feature 🔨 新功能,新特性 label Nov 11, 2022
@gmf520
Copy link
Member Author

gmf520 commented Nov 11, 2022

已在分支 /dev/snow 提供实现

@gmf520 gmf520 added the Finished ✔️ 实现并完工 label Nov 11, 2022
@waleswood
Copy link
Contributor

建议将雪花id的workerId暴露出来可以配置,目前是写死的
services.TryAddSingleton<IKeyGenerator<long>>(new SnowKeyGenerator(new DefaultIdGenerator(new IdGeneratorOptions(1))));

@gmf520
Copy link
Member Author

gmf520 commented Aug 23, 2023

@waleswood 这个用的是TryAddSingleton,只要你在这个之前注册一个IKeyGenerator<long>,这行就不起作用了

@gmf520 gmf520 added this to the v7.0.0 milestone Oct 2, 2023
@gmf520 gmf520 closed this as completed Oct 2, 2023
@waleswood
Copy link
Contributor

是的,我也可以移除再添加。不过我觉得这样不够优雅

@lianglj
Copy link

lianglj commented Oct 30, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature 🔨 新功能,新特性 Finished ✔️ 实现并完工
Projects
None yet
Development

No branches or pull requests

3 participants