mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-05 04:05:18 +08:00
feat: 机器新增备注字段,其他优化
This commit is contained in:
@@ -162,7 +162,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
|
||||
}
|
||||
|
||||
// 最大连接周期,超过时间的连接就close
|
||||
DB.SetConnMaxLifetime(100 * time.Second)
|
||||
// DB.SetConnMaxLifetime(100 * time.Second)
|
||||
// 设置最大连接数
|
||||
DB.SetMaxOpenConns(2)
|
||||
// 设置闲置连接数
|
||||
@@ -182,7 +182,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
|
||||
var dbCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(key interface{}, value interface{}) {
|
||||
global.Log.Info(fmt.Sprintf("删除db连接缓存 id: %s", key))
|
||||
global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
|
||||
value.(*DbInstance).Close()
|
||||
})
|
||||
|
||||
@@ -307,13 +307,9 @@ func getDsn(d *entity.Db) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 关闭该数据库所有连接
|
||||
// 删除db缓存并关闭该数据库所有连接
|
||||
func CloseDb(dbId uint64, db string) {
|
||||
id := GetDbCacheKey(dbId, db)
|
||||
if di := GetDbInstanceByCache(id); di != nil {
|
||||
di.Close()
|
||||
dbCache.Delete(id)
|
||||
}
|
||||
dbCache.Delete(GetDbCacheKey(dbId, db))
|
||||
}
|
||||
|
||||
//-----------------------------------元数据-------------------------------------------
|
||||
|
||||
@@ -51,7 +51,10 @@ func (m *machineAppImpl) Count(condition *entity.Machine) int64 {
|
||||
|
||||
// 根据条件获取机器信息
|
||||
func (m *machineAppImpl) Save(me *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(machine.TestConn(me), "该机器无法连接: %s")
|
||||
// ’修改机器信息且密码不为空‘ or ‘新增’需要测试是否可连接
|
||||
if (me.Id != 0 && me.Password != "") || me.Id == 0 {
|
||||
biz.ErrIsNilAppendErr(machine.TestConn(me), "该机器无法连接: %s")
|
||||
}
|
||||
|
||||
oldMachine := &entity.Machine{Ip: me.Ip, Port: me.Port, Username: me.Username}
|
||||
err := m.GetMachine(oldMachine)
|
||||
|
||||
@@ -126,7 +126,7 @@ func (r *redisAppImpl) GetRedisInstance(id uint64) *RedisInstance {
|
||||
var redisCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(key interface{}, value interface{}) {
|
||||
global.Log.Info(fmt.Sprintf("删除redis连接缓存 id: %d", key))
|
||||
global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %d", key))
|
||||
value.(*RedisInstance).Cli.Close()
|
||||
})
|
||||
|
||||
@@ -137,12 +137,9 @@ type RedisInstance struct {
|
||||
Cli *redis.Client
|
||||
}
|
||||
|
||||
// 关闭redis连接
|
||||
// 移除redis连接缓存并关闭redis连接
|
||||
func CloseRedis(id uint64) {
|
||||
if load, ok := redisCache.Get(id); ok {
|
||||
load.(*RedisInstance).Cli.Close()
|
||||
redisCache.Delete(id)
|
||||
}
|
||||
redisCache.Delete(id)
|
||||
}
|
||||
|
||||
func TestRedisConnection(re *entity.Redis) {
|
||||
|
||||
Reference in New Issue
Block a user