2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 07:57:21 +08:00

fix: redis支持设置密码情况下查看负载

This commit is contained in:
耗子
2025-01-06 04:57:05 +08:00
parent 6de5e799ea
commit 7a648097d2

View File

@@ -3,6 +3,7 @@ package redis
import (
"fmt"
"net/http"
"regexp"
"strings"
"github.com/go-chi/chi/v5"
@@ -38,7 +39,20 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
return
}
raw, err := shell.Execf("redis-cli info")
// 检查 Redis 密码
withPassword := ""
config, err := io.Read(fmt.Sprintf("%s/server/redis/redis.conf", app.Root))
if err != nil {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
}
re := regexp.MustCompile(`requirepass\s+(.+)`)
matches := re.FindStringSubmatch(config)
if len(matches) == 2 {
withPassword = " -a " + matches[1]
}
raw, err := shell.Execf("redis-cli%s info", withPassword)
if err != nil {
service.Error(w, http.StatusInternalServerError, "获取 Redis 负载失败")
return