SnowflakeId.AutoRegister.SqlServer
1.0.1
dotnet add package SnowflakeId.AutoRegister.SqlServer --version 1.0.1
NuGet\Install-Package SnowflakeId.AutoRegister.SqlServer -Version 1.0.1
<PackageReference Include="SnowflakeId.AutoRegister.SqlServer" Version="1.0.1" />
paket add SnowflakeId.AutoRegister.SqlServer --version 1.0.1
#r "nuget: SnowflakeId.AutoRegister.SqlServer, 1.0.1"
// Install SnowflakeId.AutoRegister.SqlServer as a Cake Addin #addin nuget:?package=SnowflakeId.AutoRegister.SqlServer&version=1.0.1 // Install SnowflakeId.AutoRegister.SqlServer as a Cake Tool #tool nuget:?package=SnowflakeId.AutoRegister.SqlServer&version=1.0.1
SnowflakeId AutoRegister
Is a C# library for automatic registration of WorkerId in SnowflakeId systems,
supporting SQL Server, Redis , and other.
Itself does not provide the generation of Snowflake Id, it only helps you to automatically register WorkerId.
In theory, SnowflakeId AutoRegister can be integrated with any framework that utilizes SnowflakeId
Getting Started
SnowflakeId AutoRegister is a library that provides a simple way to automatically register WorkerId in SnowflakeId
systems.
Itself does not provide the generation of Snowflake Id, it only helps you to automatically register WorkerId.
Prerequisites
- .NETStandard 2.0
- Support Redis
- Support SQL Server
- More storage mechanisms will be supported in future updates
Installation
SnowflakeId.AutoRegister is available as a NuGet package. You can install it using the NuGet Package Console window:
Install the core package
Install-Package SnowflakeId.AutoRegister
Use Redis
Install-Package SnowflakeId.AutoRegister.Redis
Use SqlServer
Install-Package SnowflakeId.AutoRegister.SqlServer
Usage
Use the AutoRegisterBuilder
to create a singleton instance of IAutoRegister
.
static readonly IAutoRegister AutoRegister = new AutoRegisterBuilder()
// Register Option
// Use the following line to set the identifier.
// Recommended setting to distinguish multiple applications on a single machine
.SetExtraIdentifier(Environment.CurrentDirectory)
// Use the following line to set the WorkerId scope.
.SetWorkerIdScope(1, 31)
// Use the following line to set the register option.
// .SetRegisterOption(option => {})
// Use the following line to use the default store.
// Only suitable for standalone use, local testing, etc.
//.UseDefaultStore()
// Use the following line to use the Redis store.
.UseRedisStore("localhost:6379,allowAdmin=true")
// Use the following line to use the SQL Server store.
//.UseSqlServerStore("Server=localhost;Database=IdGenerator;User Id=sa;Password=123456;")
Build();
Use the AutoRegister
instance to get the SnowflakeIdConfig.
// Use Register WorkerId.
SnowflakeIdConfig config = AutoRegister.Register();
Console.WriteLine($"WorkerId: {config.WorkerId}");
Yitter.IdGenerator AutoRegister
var config = AutoRegister.Register();
var options = new IdGeneratorOptions
{
WorkerId = (ushort)config.WorkerId,
};
IIdGenerator idGenInstance = new DefaultIdGenerator(options);
long id = idGenInstance.NewLong();
Console.WriteLine($"Id: {id}");
Other AutoRegister
For other Snowflake ID generation libraries, please refer to the Yitter.IdGenerator Demo.
Building the sources
Clone the repository:
git clone https://github.com/LemonNoCry/SnowflakeId.AutoRegister.git
Navigate to the project directory:
cd SnowflakeId.AutoRegister
Restore the packages:
dotnet restore
Build the project:
dotnet build
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- Dapper (>= 2.1.35)
- Microsoft.Bcl.AsyncInterfaces (>= 5.0.0)
- Microsoft.Data.SqlClient (>= 3.1.5)
- SnowflakeId.AutoRegister (>= 1.0.1)
-
.NETStandard 2.0
- Dapper (>= 2.1.35)
- Microsoft.Bcl.AsyncInterfaces (>= 5.0.0)
- Microsoft.Data.SqlClient (>= 5.2.1)
- SnowflakeId.AutoRegister (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on SnowflakeId.AutoRegister.SqlServer:
Repository | Stars |
---|---|
anjoy8/Blog.Core
💖 ASP.NET Core 8.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
|