db connection lost #222

This commit is contained in:
lealife
2015-10-10 14:49:02 +08:00
parent 0479f1a433
commit 70ee362cc8
2 changed files with 22 additions and 1 deletions

View File

@ -355,3 +355,20 @@ func Err(err error) bool {
}
return true
}
// 检查mognodb是否lost connection
// 每个请求之前都要检查!!
func CheckMongoSessionLost() {
// fmt.Println("检查CheckMongoSessionLostErr")
err := Session.Ping()
if err != nil {
Log("Lost connection to db!")
Session.Refresh()
err = Session.Ping()
if err == nil {
Log("Reconnect to db successful.")
} else {
Log("重连失败!!!! 警告")
}
}
}