From c9ce8498d2902bd87ce291e3e9d5fafdb48c95e1 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 17 Mar 2023 12:40:50 +0300 Subject: [PATCH] fix double init with empty context error Signed-off-by: Vasiliy Tolstov --- go.mod | 3 ++- go.sum | 4 ++++ redis.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 28e0c85..7a8781a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,8 @@ module go.unistack.org/micro-store-redis/v3 go 1.16 require ( + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/go-redis/redis/v8 v8.11.5 - go.unistack.org/micro/v3 v3.10.14 + go.unistack.org/micro/v3 v3.10.18 golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect ) diff --git a/go.sum b/go.sum index ca709bc..e65d757 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -53,6 +55,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.unistack.org/micro/v3 v3.10.14 h1:7fgLpwGlCN67twhwtngJDEQvrMkUBDSA5vzZqxIDqNE= go.unistack.org/micro/v3 v3.10.14/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q= +go.unistack.org/micro/v3 v3.10.18 h1:iz193N8eZKGrKPXuX6XMsGIRHMqdvUaZSfb9mzwlUYM= +go.unistack.org/micro/v3 v3.10.18/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q= 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= diff --git a/redis.go b/redis.go index 1b5a93c..c4b3d3b 100755 --- a/redis.go +++ b/redis.go @@ -260,6 +260,10 @@ func (r *rkv) configure() error { nodes = []string{"redis://127.0.0.1:6379"} } + if r.cli != nil && r.opts.Context == nil { + return nil + } + if r.opts.Context != nil { if c, ok := r.opts.Context.Value(configKey{}).(*redis.Options); ok { redisOptions = c @@ -280,12 +284,17 @@ func (r *rkv) configure() error { return fmt.Errorf("must specify only one option Config or ClusterConfig") } + if redisOptions == nil && redisClusterOptions == nil && r.cli != nil { + return nil + } + if redisOptions == nil && redisClusterOptions == nil && len(nodes) == 1 { redisOptions, err = redis.ParseURL(nodes[0]) if err != nil { // Backwards compatibility redisOptions = &redis.Options{ Addr: nodes[0], + Username: "", Password: "", // no password set DB: 0, // use default DB MaxRetries: 2, @@ -302,6 +311,7 @@ func (r *rkv) configure() error { } else if redisOptions == nil && redisClusterOptions == nil && len(nodes) > 1 { redisClusterOptions = &redis.ClusterOptions{ Addrs: nodes, + Username: "", Password: "", // no password set MaxRetries: 2, MaxRetryBackoff: 256 * time.Millisecond, -- 2.45.2