Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hueifeng/snowflake-csharp

Twitter's SnowFlake algorithm is implemented using C# language. Support on redis to determine the machine serial number, Full support of cloud native K8S.
https://github.com/hueifeng/snowflake-csharp

csharp distributed kubernetes redis snowflake snowflake-algorithm twitter unique-id

Last synced: 10 days ago
JSON representation

Twitter's SnowFlake algorithm is implemented using C# language. Support on redis to determine the machine serial number, Full support of cloud native K8S.

Awesome Lists containing this project

README

        





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




















## Description

Language: English | [中文](README.zh-cn.md)

Twitter's SnowFlake algorithm is implemented using C# language.

## Installation

```
PM> Install-Package Snowflake.CSharp
```

## Useage

1. Specify the data center ID and machine ID.

```csharp
SnowFlake snowFlake = new SnowFlake(datacenterId:1,machineId:1);
```

2. Generate Id.

```csharp
var id = snowFlake.NextId();
```

## Advanced

Support Kubernetes HorizontalPodAutoscaler.

1. Used in distributed.

```
PM> Install-Package Snowflake.Redis.CSharp
```

2. Add the following code at ConfigureServices() method.

```csharp

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"
}
```

## License

[Apache](LICENSE)