1. Mongo dial add 5 seconds connection timeout.
 2. Redis uses connection pool mode.
 3. Redis pool new connection have 10 seconds write timeout and read timeout and connection timeout.
This commit is contained in:
yaziming
2019-09-01 17:18:08 +08:00
parent d97134b288
commit 443d697c6f
9 changed files with 166 additions and 160 deletions

View File

@@ -3,6 +3,7 @@ package database
import (
"github.com/globalsign/mgo"
"github.com/spf13/viper"
"time"
)
var Session *mgo.Session
@@ -44,7 +45,7 @@ func InitMongo() error {
} else {
uri = "mongodb://" + mongoUsername + ":" + mongoPassword + "@" + mongoHost + ":" + mongoPort + "/" + mongoDb + "?authSource=" + mongoAuth
}
sess, err := mgo.Dial(uri)
sess, err := mgo.DialWithTimeout(uri, time.Second*5)
if err != nil {
return err
}