redis配置默认值

This commit is contained in:
suguo.yao 2023-10-31 14:03:34 +08:00
parent 9b7f627b0f
commit 8de9252ae5
1 changed files with 25 additions and 19 deletions

View File

@ -22,14 +22,20 @@ type Config struct {
// Init init
func Init(opts *Config) error {
if opts == nil {
opts = &Config{
Host: "127.0.0.1:6379",
Password: "",
Database: 0,
MaxIdle: 10,
MaxActive: 100,
IdleTimeout: 600,
opts = &Config{}
}
if opts.Host == "" {
opts.Host = "127.0.0.1:6379"
}
if opts.MaxIdle == 0 {
opts.MaxIdle = 1
}
if opts.MaxActive == 0 {
opts.MaxActive = 10
}
if opts.IdleTimeout == 0 {
opts.IdleTimeout = 600
}
pool = &redigo.Pool{