From cd36cf1e62bc3c11e9ae3dad521adaacc202f72b Mon Sep 17 00:00:00 2001 From: yitter Date: Fri, 2 Apr 2021 22:47:13 +0800 Subject: [PATCH] auto commit --- Go/source/go.mod | 6 +---- Go/source/go.sum | 21 ++++++++++++++++ Go/source/regworkerid/reghelper.go | 40 +++++++++++++++++------------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Go/source/go.mod b/Go/source/go.mod index 6a111a2..f40ef34 100644 --- a/Go/source/go.mod +++ b/Go/source/go.mod @@ -2,8 +2,4 @@ module yitidgen go 1.14 -require ( - github.com/go-redis/redis v6.15.9+incompatible - github.com/onsi/ginkgo v1.15.2 // indirect - github.com/onsi/gomega v1.11.0 // indirect -) +require github.com/go-redis/redis/v8 v8.8.0 // indirect diff --git a/Go/source/go.sum b/Go/source/go.sum index b98c3ea..3e2ce7f 100644 --- a/Go/source/go.sum +++ b/Go/source/go.sum @@ -1,8 +1,15 @@ +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= +github.com/go-redis/redis/v8 v8.8.0 h1:fDZP58UN/1RD3DjtTXP/fFZ04TFohSYhjZDkcDe2dnw= +github.com/go-redis/redis/v8 v8.8.0/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -16,19 +23,32 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/ginkgo v1.15.2 h1:l77YT15o814C2qVL47NOyjV/6RbaP7kKdrvZnxQ3Org= github.com/onsi/ginkgo v1.15.2/go.mod h1:Dd6YFfwBW84ETqqtL0CPyPXillHgY6XhQH3uuCCTr/o= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug= github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= +go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= +go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= +go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= +go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= +go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= +go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -80,3 +100,4 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/Go/source/regworkerid/reghelper.go b/Go/source/regworkerid/reghelper.go index e628a2f..d4df7b6 100644 --- a/Go/source/regworkerid/reghelper.go +++ b/Go/source/regworkerid/reghelper.go @@ -1,14 +1,16 @@ package regworkerid import ( + "context" "fmt" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" "strconv" "sync" "time" ) var _client *redis.Client +var _ctx = context.Background() var _workerIdLock sync.Mutex var _usingWorkerId int = -1 // 当前已注册的WorkerId @@ -40,10 +42,12 @@ func UnRegisterWorkerId() { } _workerIdLock.Lock() - _client.Del(_WorkerIdValueKeyPrefix + strconv.Itoa(_usingWorkerId)) + _client.Del(_ctx, _WorkerIdValueKeyPrefix+strconv.Itoa(_usingWorkerId)) _usingWorkerId = -1 _lifeIndex = -1 _workerIdLock.Unlock() + + _client.Quit(_ctx) } func RegisterWorkerId(ip string, port int, password string, maxWorkerId int) int { @@ -60,13 +64,15 @@ func RegisterWorkerId(ip string, port int, password string, maxWorkerId int) int _MaxWorkerId = maxWorkerId _client = redis.NewClient(&redis.Options{ Addr: ip + ":" + strconv.Itoa(port), - PoolSize: 1000, - ReadTimeout: time.Millisecond * time.Duration(100), - WriteTimeout: time.Millisecond * time.Duration(100), - IdleTimeout: time.Second * time.Duration(60), Password: password, + DB: 0, + //PoolSize: 1000, + //ReadTimeout: time.Millisecond * time.Duration(100), + //WriteTimeout: time.Millisecond * time.Duration(100), + //IdleTimeout: time.Second * time.Duration(60), }) - _, err := _client.Ping().Result() + + _, err := _client.Ping(_ctx).Result() if err != nil { panic("init redis error") } else { @@ -81,7 +87,7 @@ func RegisterWorkerId(ip string, port int, password string, maxWorkerId int) int func getNextWorkerId() int { // 获取当前 WorkerIdIndex - r, err := _client.Incr(_WorkerIdIndexKey).Result() + r, err := _client.Incr(_ctx, _WorkerIdIndexKey).Result() if err != nil { return 0 } @@ -180,7 +186,7 @@ func extendWorkerIdLifeTime(lifeIndex int) { } func get(key string) (string, bool) { - r, err := _client.Get(key).Result() + r, err := _client.Get(_ctx, key).Result() if err != nil { return "", false } @@ -188,23 +194,23 @@ func get(key string) (string, bool) { } func set(key string, val string, expTime int32) { - _client.Set(key, val, time.Duration(expTime)*time.Second) + _client.Set(_ctx, key, val, time.Duration(expTime)*time.Second) } func setWorkerIdIndex(val int) { - _client.Set(_WorkerIdIndexKey, val, 0) + _client.Set(_ctx, _WorkerIdIndexKey, val, 0) } func setWorkerIdFlag(index int) { - _client.Set(_WorkerIdValueKeyPrefix+strconv.Itoa(index), _WorkerIdFlag, time.Duration(_WorkerIdLifeTimeSeconds)*time.Second) + _client.Set(_ctx, _WorkerIdValueKeyPrefix+strconv.Itoa(index), _WorkerIdFlag, time.Duration(_WorkerIdLifeTimeSeconds)*time.Second) } func extendWorkerIdFlag(index int) { - _client.Expire(_WorkerIdValueKeyPrefix+strconv.Itoa(index), time.Duration(_WorkerIdLifeTimeSeconds)*time.Second) + _client.Expire(_ctx, _WorkerIdValueKeyPrefix+strconv.Itoa(index), time.Duration(_WorkerIdLifeTimeSeconds)*time.Second) } func canReset() bool { - r, err := _client.Incr(_WorkerIdValueKeyPrefix + "Edit").Result() + r, err := _client.Incr(_ctx, _WorkerIdValueKeyPrefix+"Edit").Result() if err != nil { return false } @@ -218,11 +224,11 @@ func canReset() bool { func endReset() { // _client.Set(_WorkerIdValueKeyPrefix+"Edit", 0, time.Duration(2)*time.Second) - _client.Set(_WorkerIdValueKeyPrefix+"Edit", 0, 0) + _client.Set(_ctx, _WorkerIdValueKeyPrefix+"Edit", 0, 0) } func getWorkerIdFlag(index int) (string, bool) { - r, err := _client.Get(_WorkerIdValueKeyPrefix + strconv.Itoa(index)).Result() + r, err := _client.Get(_ctx, _WorkerIdValueKeyPrefix+strconv.Itoa(index)).Result() if err != nil { return "", false } @@ -230,7 +236,7 @@ func getWorkerIdFlag(index int) (string, bool) { } func isAvailable(index int) bool { - r, err := _client.Get(_WorkerIdValueKeyPrefix + strconv.Itoa(index)).Result() + r, err := _client.Get(_ctx, _WorkerIdValueKeyPrefix+strconv.Itoa(index)).Result() if _Log { fmt.Println("XX isAvailable:" + r)