TynabXLongkunz.IdGeneratorSnowflake
2.0.0
dotnet add package TynabXLongkunz.IdGeneratorSnowflake --version 2.0.0
NuGet\Install-Package TynabXLongkunz.IdGeneratorSnowflake -Version 2.0.0
<PackageReference Include="TynabXLongkunz.IdGeneratorSnowflake" Version="2.0.0" />
paket add TynabXLongkunz.IdGeneratorSnowflake --version 2.0.0
#r "nuget: TynabXLongkunz.IdGeneratorSnowflake, 2.0.0"
// Install TynabXLongkunz.IdGeneratorSnowflake as a Cake Addin #addin nuget:?package=TynabXLongkunz.IdGeneratorSnowflake&version=2.0.0 // Install TynabXLongkunz.IdGeneratorSnowflake as a Cake Tool #tool nuget:?package=TynabXLongkunz.IdGeneratorSnowflake&version=2.0.0
ID GENERATOR SNOWFLAKE
IdGeneratorSnowflake is a C# library that provides a unique ID generation mechanism based on the Snowflake algorithm. It allows you to generate globally unique IDs with the ability to specify Worker ID and Datacenter ID.
FEATURES
- Generates unique IDs based on timestamp, Worker ID, Datacenter ID, and sequence.
- Ensures uniqueness and ordering of generated IDs.
- Supports customization of Worker ID, Datacenter ID, and initial sequence value.
- Thread-safe implementation using locking for concurrent access.
INSTALLATION
You can install the IdGeneratorSnowflake library via NuGet package manager. Run the following command in the Package Manager Console:
PM> NuGet\Install-Package TynabXLongkunz.IdGeneratorSnowflake
USAGE
To use the IdGeneratorSnowflake library, follow these steps:
- Create an instance of the IdGenerator class by providing the Worker ID and Datacenter ID:
var idGenerator = new IdGenerator(workerId, datacenterId);
- Generate a new unique ID by calling the NextId method:
var id = idGenerator.NextId();
The generated ID will be a 64-bit unsigned integer (ulong) value.
THREAD SAFETY
The IdGenerator class provided by IdGeneratorSnowflake is thread-safe. It utilizes locking to synchronize access to shared variables and ensure correct generation of unique IDs in a multi-threaded environment.
LICENSE
IdGeneratorSnowflake is licensed under the MIT License.
ACKNOWLEDGEMENTS
IdGeneratorSnowflake is inspired by the Snowflake algorithm, originally developed by Twitter.
If you have any suggestions, issues, or contributions, feel free to open an issue or pull request on the GitHub repository.
IMAGE DEMO
<p align='center'> <img src='pic/0.jpg'></img> </p>
CODE DEMO
Here's an example of generating unique IDs using the IdGeneratorSnowflake library:
// Create an instance of IdGenerator with Worker Id: 1, Datacenter Id: 2
var idGenerator = new IdGenerator(1, 2);
// Generate a new unique Id
ulong id = idGenerator.NextId();
Console.WriteLine($"Generated Id: {id}");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Upgrade:
- Input Timestamp Epoch (optional)
- Extract with Sequence (optional)