Moving conn str and log config out of the pool thread func

This commit is contained in:
Pavel Shevaev 2022-11-07 15:18:32 +03:00
parent 5eef4a59f5
commit 8c1374c7c9
1 changed files with 7 additions and 4 deletions

11
rdb.go
View File

@ -140,18 +140,21 @@ func newRedisPool(s RdSettings, logger logr.Logger) *redis.Pool {
idleTimeoutSec = 240
}
connStr := s.ConnStr()
if len(s.Prefix) > 0 {
logger = logger.WithName("[" + s.Prefix + "]")
}
return &redis.Pool{
Wait: false,
MaxIdle: maxIdle,
IdleTimeout: time.Second * time.Duration(idleTimeoutSec),
Dial: func() (redis.Conn, error) {
orig, err := redis.Dial("tcp", s.ConnStr())
orig, err := redis.Dial("tcp", connStr)
if err != nil {
return nil, errors.WithStack(err)
}
if len(s.Prefix) > 0 {
logger = logger.WithName("[" + s.Prefix + "]")
}
c := &rdb{
orig: orig,
name: s.Prefix,