當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.Run方法代碼示例

本文整理匯總了Golang中labix/org/v2/mgo.Session.Run方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Run方法的具體用法?Golang Session.Run怎麽用?Golang Session.Run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在labix/org/v2/mgo.Session的用法示例。


在下文中一共展示了Session.Run方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CurrentStatus

// CurrentStatus returns the status of the replica set for the given session.
func CurrentStatus(session *mgo.Session) (*Status, error) {
	status := &Status{}
	err := session.Run("replSetGetStatus", status)
	if err != nil {
		return nil, fmt.Errorf("cannot get replica set status: %v", err)
	}
	return status, nil
}
開發者ID:jimmiebtlr,項目名稱:juju,代碼行數:9,代碼來源:replicaset.go

示例2: IsMaster

// IsMaster returns information about the configuration of the node that
// the given session is connected to.
func IsMaster(session *mgo.Session) (*IsMasterResults, error) {
	results := &IsMasterResults{}
	err := session.Run("isMaster", results)
	if err != nil {
		return nil, err
	}
	return results, nil
}
開發者ID:jimmiebtlr,項目名稱:juju,代碼行數:10,代碼來源:replicaset.go

示例3: Optime

// Optime returns the Timestamp for mongo getoptime command, session should be a direct session.
func Optime(s *mgo.Session) (*Timestamp, error) {
	ts := new(Timestamp)

	stats := struct {
		Optime optime
	}{}

	if err := s.Run("getoptime", &stats); err != nil {
		return ts, err
	}

	*ts = Timestamp(stats.Optime)
	return ts, nil
}
開發者ID:ehogberg,項目名稱:cryriver,代碼行數:15,代碼來源:tail.go

示例4: 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
}
開發者ID:jimmiebtlr,項目名稱:juju,代碼行數:28,代碼來源:replicaset.go


注:本文中的labix/org/v2/mgo.Session.Run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。