Merge pull request 'fix double init with empty context error' (#106) from init-fix into v3
Reviewed-on: #106
This commit is contained in:
commit
97e30b0122
3
go.mod
3
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
|
||||
)
|
||||
|
4
go.sum
4
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=
|
||||
|
10
redis.go
10
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user