1
0
mirror of synced 2025-12-24 14:07:57 +08:00

auto commit

This commit is contained in:
yitter
2021-04-02 22:22:55 +08:00
parent e494b91cae
commit 84d1d67dcb
22 changed files with 95 additions and 314 deletions

View File

@@ -4,14 +4,13 @@ import (
"C"
"fmt"
"time"
"yitidgen/contract"
"yitidgen/idgen"
"yitidgen/regworkerid"
)
///export SetOptions
func SetOptions(workerId uint16) {
var options = contract.NewIdGeneratorOptions(workerId)
var options = idgen.NewIdGeneratorOptions(workerId)
idgen.SetIdGenerator(options)
}
@@ -44,23 +43,21 @@ func main() {
fmt.Println("注册的WorkerId:", regworkerid.RegisterWorkerId("localhost", 6379, "", 4))
return
// 方法二:自定义参数
var options = contract.NewIdGeneratorOptions(1)
var options = idgen.NewIdGeneratorOptions(1)
options.WorkerIdBitLength = 6
options.SeqBitLength = 6
options.TopOverCostCount = 2000
options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6
idgen.SetIdGenerator(options)
var genCount = 50000
for {
var begin = time.Now().UnixNano() / 1e6
var begin = time.Now().UnixNano() / 1e3
for i := 0; i < genCount; i++ {
idgen.NextId()
}
var end = time.Now().UnixNano() / 1e6
var end = time.Now().UnixNano() / 1e3
fmt.Println(end - begin)
time.Sleep(time.Duration(1000) * time.Millisecond)
@@ -70,6 +67,3 @@ func main() {
// go build -o target\yitidgengo.dll -buildmode=c-shared main.go
//var yid = idgen.YitIdHelper{}
//yid.SetIdGenerator(options)
//fmt.Println(yid.NextId())