本文整理汇总了Golang中labix/org/v2/mgo.Session.Refresh方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Refresh方法的具体用法?Golang Session.Refresh怎么用?Golang Session.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类labix/org/v2/mgo.Session
的用法示例。
在下文中一共展示了Session.Refresh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: applyRelSetConfig
// applyRelSetConfig applies the new config to the mongo session. It also logs
// what the changes are. It checks if the replica set changes cause the DB
// connection to be dropped. If so, it Refreshes the session and tries to Ping
// again.
func applyRelSetConfig(cmd string, session *mgo.Session, oldconfig, newconfig *Config) error {
logger.Debugf("%s() changing replica set\nfrom %s\n to %s",
cmd, fmtConfigForLog(oldconfig), fmtConfigForLog(newconfig))
err := session.Run(bson.D{{"replSetReconfig", newconfig}}, nil)
// We will only try to Ping 2 times
for i := 0; i < 2; i++ {
if err == io.EOF {
// If the primary changes due to replSetReconfig, then all
// current connections are dropped.
// Refreshing should fix us up.
logger.Debugf("got EOF while running %s(), calling session.Refresh()", cmd)
session.Refresh()
} else if err != nil {
// For all errors that aren't EOF, return immediately
return err
}
// err is either nil or EOF and we called Refresh, so Ping to
// make sure we're actually connected
err = session.Ping()
// Change the command because it is the new command we ran
cmd = "Ping"
}
return err
}