add redis connect from pool timeout
This commit is contained in:
parent
c2309da7b0
commit
405167719f
12
model.go
12
model.go
@ -1,9 +1,11 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qoobing.com/gomod/gorm"
|
"qoobing.com/gomod/gorm"
|
||||||
"qoobing.com/gomod/log"
|
"qoobing.com/gomod/log"
|
||||||
@ -127,7 +129,15 @@ func RedisOf(name string) redis.Conn {
|
|||||||
if !ok {
|
if !ok {
|
||||||
panic(errNoModelFound(name))
|
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 {
|
func RedisPool() *redis.Pool {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user