mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-28 18:25:05 +08:00
mysql 增加一个连接池设置
This commit is contained in:
@@ -206,7 +206,7 @@ func (slf *DBResult) mapSlice2interface(data []map[string]string, in interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect ...
|
// Connect ...
|
||||||
func (slf *DBModule) Connect() error {
|
func (slf *DBModule) Connect(maxConn int) error {
|
||||||
cmd := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true&loc=%s",
|
cmd := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true&loc=%s",
|
||||||
slf.UserName,
|
slf.UserName,
|
||||||
slf.Password,
|
slf.Password,
|
||||||
@@ -225,6 +225,10 @@ func (slf *DBModule) Connect() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
slf.db = db
|
slf.db = db
|
||||||
|
db.SetMaxOpenConns(maxConn)
|
||||||
|
db.SetMaxIdleConns(maxConn)
|
||||||
|
db.SetConnMaxLifetime(time.Second * 90)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func TestDBModule(t *testing.T) {
|
|||||||
Password: "Root!!2018",
|
Password: "Root!!2018",
|
||||||
DBName: "QuantFundsDB",
|
DBName: "QuantFundsDB",
|
||||||
}
|
}
|
||||||
db.Connect()
|
db.Connect(100)
|
||||||
|
|
||||||
res := db.Query("select * from tbl_fun_heelthrow where id >= 1")
|
res := db.Query("select * from tbl_fun_heelthrow where id >= 1")
|
||||||
if res.Err != nil {
|
if res.Err != nil {
|
||||||
@@ -26,7 +26,7 @@ func TestDBModule(t *testing.T) {
|
|||||||
Uuid string `json:"uuid,omitempty"`
|
Uuid string `json:"uuid,omitempty"`
|
||||||
AAAA string `json:"xxx"`
|
AAAA string `json:"xxx"`
|
||||||
}{}
|
}{}
|
||||||
err := res.SetSpecificTag("json").SetBlurMode(false).UnMarshal(&out)
|
err := res.SetSpecificTag("json").SetBlurMode(true).UnMarshal(&out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user