auto commit
This commit is contained in:
@@ -8,21 +8,25 @@
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.*" />
|
||||
```
|
||||
|
||||
## 调用示例
|
||||
## 调用示例(C#)
|
||||
|
||||
调用过程分为2步,第1步是全局初始化(应用程序启动时执行一次),第2步是生成ID,代码如下:
|
||||
|
||||
```
|
||||
// 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置)
|
||||
var options = new IdGeneratorOptions(){ WorkerId = 1};
|
||||
// 第1步:创建 IdGeneratorOptions 对象,构造函数输入 WorkerId:
|
||||
var options = new IdGeneratorOptions(1);
|
||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||
YitIdHelper.SetIdGenerator(options);
|
||||
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||
|
||||
// 初始化以后,就可以在需要的地方调用方法生成ID。
|
||||
// 第2步:初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||
var newId = YitIdHelper.NextId();
|
||||
|
||||
```
|
||||
|
||||
如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。
|
||||
|
||||
## options 默认值及说明
|
||||
|
||||
参考源码:/Contract/IdGeneratorOptions.cs
|
||||
|
||||
## 事件说明
|
||||
|
||||
|
||||
28
Go/README.md
28
Go/README.md
@@ -1,4 +1,4 @@
|
||||
# ❄️ idenerator-go
|
||||
# ❄ idenerator-go
|
||||
|
||||
## 介绍
|
||||
项目更多介绍参照:https://github.com/yitter/idgenerator
|
||||
@@ -8,35 +8,33 @@
|
||||
1.SDK,go1.14
|
||||
|
||||
2.启用 Go-Modules
|
||||
|
||||
```
|
||||
go env -w GO111MODULE=on
|
||||
|
||||
# Next *ONLY* for China-Users:
|
||||
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
|
||||
|
||||
```
|
||||
|
||||
3. 安装方式
|
||||
|
||||
```
|
||||
go get -u -v github.com/yitter/idgenerator-go
|
||||
```
|
||||
|
||||
## Go代码示例
|
||||
## 调用示例(Go)
|
||||
|
||||
调用过程分为2步,第1步是全局初始化(应用程序启动时执行一次),第2步是生成ID,代码如下:
|
||||
|
||||
```
|
||||
|
||||
// 定义参数
|
||||
var options = idgen.NewIdGeneratorOptions(1) // 构造函数输入 WorkerId
|
||||
// options.WorkerId = 1
|
||||
// options.WorkerIdBitLength = 6
|
||||
// options.SeqBitLength = 6
|
||||
// ... 以上参数一般不需要设置,系统有默认值
|
||||
// 第1步:创建 IdGeneratorOptions 对象,构造函数输入 WorkerId:
|
||||
var options = idgen.NewIdGeneratorOptions(1)
|
||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||
idgen.SetIdGenerator(options)
|
||||
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||
|
||||
// 调用方法生成Id
|
||||
var id = idgen.NextId()
|
||||
|
||||
// 第2步:初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||
var newId = idgen.NextId()
|
||||
```
|
||||
|
||||
## 代码贡献者(按时间顺序)
|
||||
|
||||
@@ -12,23 +12,23 @@ JDK 1.8+
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## 调用示例
|
||||
## 调用示例(Java)
|
||||
|
||||
调用过程分为2步,第1步是全局初始化(应用程序启动时执行一次),第2步是生成ID,代码如下:
|
||||
|
||||
```
|
||||
// 全局初始化设置WorkerId,默认最大2^16-1,可通过调整 WorkerIdBitLength 增加最大值
|
||||
IdGeneratorOptions options = new IdGeneratorOptions();
|
||||
options.WorkerId = 1;
|
||||
// 第1步:创建 IdGeneratorOptions 对象,构造函数输入 WorkerId:
|
||||
IdGeneratorOptions options = new IdGeneratorOptions(1);
|
||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||
YitIdHelper.setIdGenerator(options);
|
||||
// 以上初始化过程全局只需一次,且必须最先设置
|
||||
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||
|
||||
// 初始化以后,即可在需要生成ID的地方,调用以下方法。
|
||||
// 第2步:初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||
long newId = YitIdHelper.nextId();
|
||||
|
||||
```
|
||||
|
||||
如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,须使用**单例**模式。
|
||||
|
||||
|
||||
## options 默认值及说明
|
||||
|
||||
参考源码:/contract/IdGeneratorOptions.java
|
||||
|
||||
|
||||
Reference in New Issue
Block a user