add redis connect from pool timeout

This commit is contained in:
bryan 2026-01-30 22:24:05 +08:00
parent c2309da7b0
commit e7928db693

View File

@ -1,9 +1,11 @@
package model
import (
"context"
"fmt"
"reflect"
"sync"
"time"
"qoobing.com/gomod/gorm"
"qoobing.com/gomod/log"
@ -127,7 +129,15 @@ func RedisOf(name string) redis.Conn {
if !ok {
panic(errNoModelFound(name))
}
return m.redisPool.Get()
var ctx, cancelFunc = context.WithTimeout(context.Background(), 3*time.Second)
var conn, err = m.redisPool.GetContext(ctx)
if err != nil {
cancelFunc()
log.Warningf("get redis connect from pool failed, err:%s", err)
panic(err)
}
defer cancelFunc()
return conn
}
func RedisPool() *redis.Pool {