diff --git a/mymysql/mysql.go b/mymysql/mysql.go index caf8f23..bb04458 100644 --- a/mymysql/mysql.go +++ b/mymysql/mysql.go @@ -15,9 +15,9 @@ var ( DefaultConfig = &Config{ Dsn: "root:root@tcp(127.0.0.1:3306)/?loc=Local&charset=utf8mb4&parseTime=true", MaxOpenConn: 32, - MaxIdleConn: 16, - MaxLifeTime: "1h", - MaxIdleTime: "10m", + MaxIdleConn: 8, + MaxLifeTime: "4h", + MaxIdleTime: "15m", Debug: true, GormLogger: gormLogger.Default.LogMode(gormLogger.Info), } @@ -37,7 +37,7 @@ type ( } ) -func Instance(key ...string) *gorm.DB { +func DB(key ...string) *gorm.DB { var key0 string if len(key) > 0 { @@ -139,7 +139,7 @@ func NewGormLogger(writer gormLogger.Writer, gormLoggerConfig gormLogger.Config) } func CloseInstance(key string) { - db, _ := Instance(key).DB() + db, _ := DB(key).DB() db.Close() } diff --git a/mymysql/mysql_test.go b/mymysql/mysql_test.go index af7b4fb..72d5c61 100644 --- a/mymysql/mysql_test.go +++ b/mymysql/mysql_test.go @@ -23,7 +23,7 @@ func TestMysql(t *testing.T) { defer CloseAllInstance() var res = make(map[string]interface{}) - err = Instance().Table("image").Limit(1).Take(&res).Error + err = DB().Table("image").Limit(1).Take(&res).Error if err != nil { fmt.Println(err) return diff --git a/myredis/redis.go b/myredis/redis.go index 372c067..fd72c3a 100644 --- a/myredis/redis.go +++ b/myredis/redis.go @@ -17,8 +17,8 @@ var ( DB: 0, PoolSize: 16, MinIdleConn: 4, - MaxConnAge: "1h", - IdleTimeout: "10m", + MaxConnAge: "4h", + IdleTimeout: "15m", } instanceMap = make(map[string]*MyRedis) @@ -40,7 +40,7 @@ type ( } ) -func Instance(key ...string) *MyRedis { +func DB(key ...string) *MyRedis { var key0 string if len(key) > 0 { @@ -170,7 +170,7 @@ func (r *MyRedis) SetJson(key string, value interface{}, t ...time.Duration) (st } func CloseInstance(key string) { - Instance(key).Client.Close() + DB(key).Client.Close() } func CloseAllInstance() { diff --git a/myredis/redis_test.go b/myredis/redis_test.go index 2c61744..dd104a6 100644 --- a/myredis/redis_test.go +++ b/myredis/redis_test.go @@ -23,14 +23,14 @@ func TestRedis(t *testing.T) { } defer CloseAllInstance() - set, err := Instance().Set(context.Background(), "name", "qwe123", time.Minute).Result() + set, err := DB().Set(context.Background(), "name", "qwe123", time.Minute).Result() if err != nil { fmt.Println(err) return } fmt.Println(set) - get, err := Instance().Get(context.Background(), "name").Result() + get, err := DB().Get(context.Background(), "name").Result() if err != nil { fmt.Println(err) return