How to use the snowflake algorithm in .NET5

冯辉
Apr 22, 2021

--

Installation

PM> Install-Package Snowflake.CSharp

Useage

  1. Specify the data center ID and machine ID.
SnowFlake snowFlake = new SnowFlake(datacenterId:1,machineId:1);
  1. Generate Id.
var id = snowFlake.NextId();

Advanced

  1. Used in distributed
PM> Install-Package Snowflake.Redis.CSharp
  1. Add the following code at ConfigureServices() method
public void ConfigureServices(IServiceCollection services)
{
services.AddSnowflakeRedisService(connectionString:"127.0.0.1:6379,allowAdmin=true",
option
=>Configuration.GetSection("snowFlake").Bind(option)
);
}

Distributed snowflake ID automated configuration of different machine ids

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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet