!138 fix: 后端数据连接断开后报空指针异常后程序中断问题

* fix(connection):fix the bug for nil error in connection when connection reset
* fix(sqleditor): fix the spell error in sql editor
This commit is contained in:
davidathena
2025-10-18 03:15:25 +00:00
committed by Coder慌
parent 4ac57cd140
commit 4e30bdb7cc
5 changed files with 45 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package rdm
import (
"context"
"fmt"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/logx"
@@ -41,7 +42,19 @@ func (r *RedisConn) Close() error {
}
func (r *RedisConn) Ping() error {
_, err := r.Cli.Ping(context.Background()).Result()
// 首先检查r是否为nil
if r == nil {
return fmt.Errorf("redis connection is nil")
}
// 然后检查r.Cli是否为nil这是避免空指针异常的关键
if r.Cli == nil {
return fmt.Errorf("redis client is nil")
}
cmd := r.Cli.Ping(context.Background())
if cmd == nil {
return fmt.Errorf("the ping cmd is nil")
}
_, err := cmd.Result()
return err
}