本文整理匯總了Golang中github.com/dancannon/gorethink.Session.SetMaxOpenConns方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.SetMaxOpenConns方法的具體用法?Golang Session.SetMaxOpenConns怎麽用?Golang Session.SetMaxOpenConns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dancannon/gorethink.Session
的用法示例。
在下文中一共展示了Session.SetMaxOpenConns方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
config := a.NewConfig("config.gcfg")
echo := echo.New()
s := slack.New(config.Slack.Token)
var session *r.Session
session, err := r.Connect(r.ConnectOpts{
Address: fmt.Sprint(config.Database.URL, ":", config.Database.Port),
Database: config.Database.Name,
MaxIdle: 10,
MaxOpen: 10,
})
if err != nil {
log.Fatalln(err.Error())
}
session.SetMaxOpenConns(5)
r.DBCreate(config.Database.Name).Exec(session)
if err != nil {
log.Println(err)
}
_, err = r.DB(config.Database.Name).TableCreate("quotes").RunWrite(session)
if err != nil {
fmt.Print(err)
}
_, err = r.DB(config.Database.Name).TableCreate("activities").RunWrite(session)
if err != nil {
fmt.Print(err)
}
// Middleware
echo.Use(mw.Logger())
echo.Use(mw.Recover())
appcontext := &a.AppContext{
Slack: s,
Config: config,
Storage: &storage.Storage{
Name: "quotes",
URL: "192.168.10.10",
Session: session,
},
}
go appcontext.Monitor()
//Routes
a.Route(echo, appcontext)
addr := fmt.Sprintf(":%d", config.App.Port)
log.Printf("Starting server on: %s", addr)
echo.Run(addr)
}
示例2: initDb
func initDb() {
var session *r.Session
session, err := r.Connect(r.ConnectOpts{
Address: "localhost:28015",
})
if err != nil {
log.Fatalln(err.Error())
}
session.SetMaxOpenConns(5)
r.TableDrop("cars").Run(session)
resp, err := r.TableCreate("cars").RunWrite(session)
if err != nil {
log.Println(err)
}
fmt.Printf("%d table created\n", resp.TablesCreated)
s = session
}
示例3: Compute
func (bmo *BMO) Compute(input *os.File) {
var err error
var cur *r.Cursor
var session *r.Session
// set up database connection pool
session, err = r.Connect(r.ConnectOpts{
Addresses: bmo.nodes,
Database: bmo.database,
DiscoverHosts: true,
})
session.SetMaxOpenConns(POOL_SIZE)
if err != nil {
log.Fatalln(err)
}
// ensure table is present
var tableNames []string
cur, err = r.DB(bmo.database).TableList().Run(session)
if err != nil {
log.Fatalln(err)
}
cur.All(&tableNames)
set := make(map[string]bool)
for _, v := range tableNames {
set[v] = true
}
if !set[bmo.table] {
log.Println("Creating table ", bmo.table)
_, err = r.DB(bmo.database).TableCreate(bmo.table).RunWrite(session)
if err != nil {
log.Fatalln("Error creating table: ", err)
os.Exit(1)
}
}
// deliver the messages
decoder := json.NewDecoder(input)
ms := make([]Message, INSERT_BATCH_SIZE)
var m *Message
var i uint64
var ignoreLast bool
pool, _ := tunny.CreatePoolGeneric(POOL_SIZE).Open()
defer pool.Close()
table := r.Table(bmo.table)
insertOptions := r.InsertOpts{Durability: "soft"}
insert := func() {
j := i
if !ignoreLast {
j += 1
}
_, err = table.Insert(ms[:j], insertOptions).RunWrite(session)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
}
for {
i = bmo.seq % INSERT_BATCH_SIZE
m = &ms[i]
err = decoder.Decode(&m)
switch {
case err == io.EOF:
ignoreLast = true
pool.SendWork(insert)
return
case err != nil:
ignoreLast = true
pool.SendWork(insert)
log.Fatal("Can't parse json input, \"", err, "\". Object #", bmo.seq, ", after ", m)
os.Exit(1)
default:
if i+1 == INSERT_BATCH_SIZE {
ignoreLast = false
pool.SendWork(insert)
}
}
bmo.seq += 1
}
}