Skip to content

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

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}");

Pinned Loading

  1. Id-Generator-Snowflake Id-Generator-Snowflake Public

    Id Generator Snowflake

    C# 3 1

Repositories

Showing 2 of 2 repositories
  • Id-Generator-Snowflake Public

    Id Generator Snowflake

    Tynab-x-Longkunz/Id-Generator-Snowflake’s past year of commit activity
    C# 3 MIT 1 0 0 Updated Jul 29, 2024
  • .github Public archive

    Readme

    Tynab-x-Longkunz/.github’s past year of commit activity
    1 0 0 0 Updated Jun 28, 2023

Top languages

Loading…

Most used topics

Loading…