Skip to content

Commit

Permalink
fix: redis RawConfigsimplify (#537)
Browse files Browse the repository at this point in the history
Co-authored-by: papa-hexuan <hexuan@douyu.tv>
  • Loading branch information
papa-hexuan and papa-hexuan committed Nov 2, 2022
1 parent 1944d57 commit 2f5464d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 4 additions & 4 deletions pkg/client/redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func DefaultConfig() *Config {

// StdConfig ...
func StdConfig(name string) *Config {
return RawConfig(name, constant.ConfigKey("redis", name, "stub"))
return RawConfig(constant.ConfigKey("redis", name, "stub"))
}
func RawConfig(name, key string) *Config {
func RawConfig(key string) *Config {
var config = DefaultConfig()

if err := cfg.UnmarshalKey(key, &config, cfg.TagName("toml")); err != nil {
Expand All @@ -106,9 +106,9 @@ func RawConfig(name, key string) *Config {
config.Slaves.Addr = append(config.Slaves.Addr, config.Master.Addr)
}
if config.Master.Addr == "" && len(config.Slaves.Addr) == 0 {
config.logger.Panic("no master or slaves addr set:"+name, xlog.FieldName(key), xlog.FieldExtMessage(config))
config.logger.Panic("no master or slaves addr set:"+key, xlog.FieldName(key), xlog.FieldExtMessage(config))
}
config.name = name
config.name = key
if xdebug.IsDevelopmentMode() {
xdebug.PrettyJsonPrint(key, config)
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/client/redis/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ func TestStdConfig(t *testing.T) {
username=""
password="123"
[jupiter.redis.test.cluster]
dialTimeout="2s"
readTimeout="5s"
idleTimeout="60s"
`
assert.Nil(t, conf.LoadFromReader(bytes.NewBufferString(configStr), toml.Unmarshal))
t.Run("std config on addr nil", func(t *testing.T) {
var config *Config
defer func() {
if r := recover(); r != nil {
assert.Equal(t, r.(string), "no master or slaves addr set:test")
assert.Equal(t, r.(string), "no master or slaves addr set:jupiter.redis.test.stub")
assert.Nil(t, config)
}
}()
Expand Down

0 comments on commit 2f5464d

Please sign in to comment.