Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 1.4 KB

README.zh-cn.md

File metadata and controls

77 lines (53 loc) · 1.4 KB

An ID Generator for C# based on Snowflake Algorithm (Twitter announced).

nuget stats

说明

Twitter的雪花算法SnowFlake,使用csharp语言实现。

安装

PM> Install-Package Snowflake.Data -Version 1.1.2

使用

  1. 指定数据中心ID及机器ID.
SnowFlake snowFlake = new SnowFlake(datacenterId:1,machineId:1);
  1. 生成ID
var id = snowFlake.NextId();

高级

  1. 用于分布式
PM> Install-Package Snowflake.Redis.CSharp
  1. 在 ConfigureServices() 方法中添加如下代码
public void ConfigureServices(IServiceCollection services)
{
  services.AddSnowflakeRedisService(connectionString:"127.0.0.1:6379,allowAdmin=true", 
      option 
            =>Configuration.GetSection("snowFlake").Bind(option)
     );
}

分布式雪花ID不同机器ID自动化配置

"snowFlake": {
  "dataCenterId": 1,
  "Name": "test"
} 

License

Apache