Skip to content

Commit

Permalink
fix: redis支持设置密码情况下查看负载
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Jan 5, 2025
1 parent 6de5e79 commit 7a64809
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/apps/redis/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis
import (
"fmt"
"net/http"
"regexp"
"strings"

"github.com/go-chi/chi/v5"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a64809

Please sign in to comment.