@@ -1,9 +1,9 @@ | |||||
| |||||
## 运行环境 | ## 运行环境 | ||||
.NET Standard 2.0+ | .NET Standard 2.0+ | ||||
## 引用nuget包 | |||||
## 引用 nuget 包 | |||||
``` | ``` | ||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.*" /> | <PackageReference Include="Yitter.IdGenerator" Version="1.0.*" /> | ||||
``` | ``` | ||||
@@ -1,4 +1,4 @@ | |||||
# idgenerator | |||||
# idgenerator | |||||
## 编译说明 | ## 编译说明 | ||||
@@ -1,21 +1,9 @@ | |||||
# ❄ idenerator-go | |||||
# ❄ idenerator-go | |||||
## 介绍 | ## 介绍 | ||||
项目更多介绍参照:https://github.com/yitter/idgenerator | 项目更多介绍参照:https://github.com/yitter/idgenerator | ||||
## Go环境 | |||||
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 get -u -v github.com/yitter/idgenerator-go | ||||
``` | ``` | ||||
@@ -40,5 +28,18 @@ idgen.SetIdGenerator(options) | |||||
var newId = idgen.NextId() | var newId = idgen.NextId() | ||||
``` | ``` | ||||
## 关于Go环境 | |||||
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 | |||||
``` | |||||
## 代码贡献者(按时间顺序) | ## 代码贡献者(按时间顺序) | ||||
guoyahao | amuluowin | houseme | guoyahao | amuluowin | houseme | ||||
@@ -1,4 +1,4 @@ | |||||
| |||||
## 运行环境 | ## 运行环境 | ||||
JDK 1.8+ | JDK 1.8+ | ||||
@@ -1,22 +1,22 @@ | |||||
# idgenerator | |||||
锘�# idgenerator | |||||
## 调用示例(Rust) | |||||
## 璋冪敤绀轰緥锛圧ust锛� | |||||
第1步,**全局** 初始化(应用程序启动时执行一次): | |||||
绗�1姝ワ紝**鍏ㄥ眬** 鍒濆�鍖栵紙搴旂敤绋嬪簭鍚�姩鏃舵墽琛屼竴娆★級锛� | |||||
``` | ``` | ||||
// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId: | |||||
// 鍒涘缓 IdGeneratorOptions 瀵硅薄锛岃�鍦ㄦ瀯閫犲嚱鏁颁腑杈撳叆 WorkerId锛� | |||||
let mut options = IdGeneratorOptions::New(1); | let mut options = IdGeneratorOptions::New(1); | ||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength | |||||
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。 | |||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 榛樿�鍊�6锛屾敮鎸佺殑 WorkerId 鏈€澶у€间负2^6-1锛岃嫢 WorkerId 瓒呰繃64锛屽彲璁剧疆鏇村ぇ鐨� WorkerIdBitLength | |||||
// ...... 鍏跺畠鍙傛暟璁剧疆鍙傝€� IdGeneratorOptions 瀹氫箟锛屼竴鑸�潵璇达紝鍙��鍐嶈�缃� WorkerIdBitLength 锛堝喅瀹� WorkerId 鐨勬渶澶у€硷級銆� | |||||
// 保存参数(必须的操作,否则以上设置都不能生效): | |||||
// 淇濆瓨鍙傛暟锛堝繀椤荤殑鎿嶄綔锛屽惁鍒欎互涓婅�缃�兘涓嶈兘鐢熸晥锛夛細 | |||||
YitIdHelper::SetIdGenerator(options); | YitIdHelper::SetIdGenerator(options); | ||||
// 以上初始化过程只需全局一次,且必须在第2步之前设置。 | |||||
// 浠ヤ笂鍒濆�鍖栬繃绋嬪彧闇€鍏ㄥ眬涓€娆★紝涓斿繀椤诲湪绗�2姝ヤ箣鍓嶈�缃�€� | |||||
``` | ``` | ||||
第2步,生成ID: | |||||
绗�2姝ワ紝鐢熸垚ID锛� | |||||
``` | ``` | ||||
// 初始化以后,即可在任何需要生成ID的地方,调用以下方法: | |||||
// 鍒濆�鍖栦互鍚庯紝鍗冲彲鍦ㄤ换浣曢渶瑕佺敓鎴怚D鐨勫湴鏂癸紝璋冪敤浠ヤ笅鏂规硶锛� | |||||
long newId = YitIdHelper::NextId(); | long newId = YitIdHelper::NextId(); | ||||
``` | ``` | ||||
@@ -269,7 +269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||||
[[package]] | [[package]] | ||||
name = "yitidgen" | |||||
name = "yiter-idgenerator" | |||||
version = "1.0.0" | version = "1.0.0" | ||||
dependencies = [ | dependencies = [ | ||||
"chrono", | "chrono", | ||||
@@ -1,8 +1,15 @@ | |||||
[package] | [package] | ||||
name = "yitidgen" | |||||
name = "yiter-idgenerator" | |||||
version = "1.0.0" | version = "1.0.0" | ||||
authors = ["yitter <yitter@126.com>"] | authors = ["yitter <yitter@126.com>"] | ||||
edition = "2018" | edition = "2018" | ||||
license = "MIT" | |||||
description="Shorter ID and faster generation with a new snowflake drift algorithm. The core is to shorten the ID length, but also can have a very high instantaneous concurrent processing capacity (50W/0.1s), and powerful configuration capacity." | |||||
readme = "README.md" | |||||
homepage ="https://github.com/yitter/IdGenerator" | |||||
repository = "https://github.com/yitter/IdGenerator" | |||||
keywords = ["snowflake", "idgenerator"] | |||||
#categories = ["command-line-utilities"] | |||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||||
@@ -11,7 +18,7 @@ chrono = "0.4.10" | |||||
lazy_static = "1.4.0" | lazy_static = "1.4.0" | ||||
#simple_redis = "*" | #simple_redis = "*" | ||||
redis = "0.20.0" | redis = "0.20.0" | ||||
libc="*" | |||||
libc = "*" | |||||
#actix = "0.9.0" | #actix = "0.9.0" | ||||
#actix-web = "2.0" | #actix-web = "2.0" | ||||
@@ -0,0 +1,23 @@ | |||||
# idgenerator | |||||
## 调用示例(Rust) | |||||
第1步,**全局** 初始化(应用程序启动时执行一次): | |||||
``` | |||||
// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId: | |||||
let mut options = IdGeneratorOptions::New(1); | |||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength | |||||
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。 | |||||
// 保存参数(必须的操作,否则以上设置都不能生效): | |||||
YitIdHelper::SetIdGenerator(options); | |||||
// 以上初始化过程只需全局一次,且必须在第2步之前设置。 | |||||
``` | |||||
第2步,生成ID: | |||||
``` | |||||
// 初始化以后,即可在任何需要生成ID的地方,调用以下方法: | |||||
long newId = YitIdHelper::NextId(); | |||||
``` | |||||
@@ -14,17 +14,17 @@ use libc::{c_char, uint32_t}; | |||||
use std::ffi::{CStr, CString}; | use std::ffi::{CStr, CString}; | ||||
use std::str; | use std::str; | ||||
lazy_static! { | |||||
//static ref TestValue: Vec<i32> = vec!(0); | |||||
// static ref MAP: HashMap<u32, String> = HashMap::new(); | |||||
} | |||||
// lazy_static! { | |||||
// static ref TestValue: Vec<i32> = vec!(0); | |||||
// static ref MAP: HashMap<u32, String> = HashMap::new(); | |||||
// } | |||||
// // #[export_name = "SetIdGenerator"] | |||||
// #[no_mangle] | |||||
// pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) { | |||||
// YitIdHelper::SetIdGenerator(options); | |||||
// } | |||||
// #[export_name = "SetIdGenerator"] | |||||
#[no_mangle] | |||||
pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) { | |||||
YitIdHelper::SetIdGenerator(options); | |||||
} | |||||
#[no_mangle] | #[no_mangle] | ||||
pub extern "C" fn SetOptions(workerId: u32, workerIdBitLength: u8, seqBitLength: u8) { | pub extern "C" fn SetOptions(workerId: u32, workerIdBitLength: u8, seqBitLength: u8) { | ||||