From 7a648097d2d9992e35a4ee78d2717234c0676eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Mon, 6 Jan 2025 04:57:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20redis=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=AF=86=E7=A0=81=E6=83=85=E5=86=B5=E4=B8=8B=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E8=B4=9F=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/apps/redis/app.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/apps/redis/app.go b/internal/apps/redis/app.go index 8a873ac7..8383e360 100644 --- a/internal/apps/redis/app.go +++ b/internal/apps/redis/app.go @@ -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