优化 redis 配置方式

This commit is contained in:
dragon
2025-07-23 16:27:18 +08:00
parent 95f1ff4292
commit 93a26f1007

View File

@@ -36,14 +36,19 @@ func NewAutoConfig(src string) (KVConfig, error) {
return NewConfigMemory(parse.Path)
case "redis":
query := parse.Query()
addr := query.Get("addr")
pass := query.Get("pass")
if pass == "" {
pass = query.Get("password")
}
db := query.Get("db")
if db == "" {
db = "0"
}
dbi, err := strconv.Atoi(db)
if err != nil {
return nil, err
}
return NewConfigRedis(context.Background(), addr, pass, dbi)
return NewConfigRedis(context.Background(), parse.Host, pass, dbi)
default:
return nil, fmt.Errorf("unsupported scheme: %s", parse.Scheme)
}