Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redis RawConfigsimplify #537

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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