update
parent
0b36406c6f
commit
7fe58f3725
|
@ -138,12 +138,12 @@ func NewGormLogger(writer gormLogger.Writer, gormLoggerConfig gormLogger.Config)
|
||||||
return gormLogger.New(writer, gormLoggerConfig)
|
return gormLogger.New(writer, gormLoggerConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseInstance(key string) {
|
func CloseDB(key string) {
|
||||||
db, _ := DB(key).DB()
|
db, _ := DB(key).DB()
|
||||||
db.Close()
|
db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseAllInstance() {
|
func CloseAllDB() {
|
||||||
for _, v := range instanceMap {
|
for _, v := range instanceMap {
|
||||||
db, _ := v.DB()
|
db, _ := v.DB()
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestMysql(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer CloseAllInstance()
|
defer CloseAllDB()
|
||||||
|
|
||||||
var res = make(map[string]interface{})
|
var res = make(map[string]interface{})
|
||||||
err = DB().Table("image").Limit(1).Take(&res).Error
|
err = DB().Table("image").Limit(1).Take(&res).Error
|
||||||
|
|
|
@ -169,11 +169,11 @@ func (r *MyRedis) SetJson(key string, value interface{}, t ...time.Duration) (st
|
||||||
return r.Client.Set(ctx, key, v, t2).Result()
|
return r.Client.Set(ctx, key, v, t2).Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseInstance(key string) {
|
func CloseDB(key string) {
|
||||||
DB(key).Client.Close()
|
DB(key).Client.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseAllInstance() {
|
func CloseAllDB() {
|
||||||
for _, v := range instanceMap {
|
for _, v := range instanceMap {
|
||||||
v.Client.Close()
|
v.Client.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestRedis(t *testing.T) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer CloseAllInstance()
|
defer CloseAllDB()
|
||||||
|
|
||||||
set, err := DB().Set(context.Background(), "name", "qwe123", time.Minute).Result()
|
set, err := DB().Set(context.Background(), "name", "qwe123", time.Minute).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue