TynabXLongkunz.IdGeneratorSnowflake 2.0.0

dotnet add package TynabXLongkunz.IdGeneratorSnowflake --version 2.0.0                
NuGet\Install-Package TynabXLongkunz.IdGeneratorSnowflake -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TynabXLongkunz.IdGeneratorSnowflake" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TynabXLongkunz.IdGeneratorSnowflake --version 2.0.0                
#r "nuget: TynabXLongkunz.IdGeneratorSnowflake, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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:

  1. Create an instance of the IdGenerator class by providing the Worker ID and Datacenter ID:
    var idGenerator = new IdGenerator(workerId, datacenterId);
    
  2. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
2.0.0 72 7/29/2024
1.0.2 384 6/28/2023
1.0.1 141 6/14/2023
1.0.0 147 6/8/2023

Upgrade:
- Input Timestamp Epoch (optional)
- Extract with Sequence (optional)