1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-20 00:39:17 +08:00
1Panel/backend/app/service/database_test.go

36 lines
726 B
Go
Raw Normal View History

2022-10-21 18:50:38 +08:00
package service
import (
2022-11-03 23:42:42 +08:00
"encoding/json"
2022-10-21 18:50:38 +08:00
"fmt"
2022-11-03 23:42:42 +08:00
"os/exec"
"strings"
2022-10-21 18:50:38 +08:00
"testing"
2022-10-31 17:26:15 +08:00
"github.com/1Panel-dev/1Panel/backend/app/dto"
2022-10-21 18:50:38 +08:00
)
func TestMysql(t *testing.T) {
2022-11-03 23:42:42 +08:00
cmd := exec.Command("docker", "exec", "1Panel-redis-7.0.5-zgVH-K859", "redis-cli", "config", "get", "save")
stdout, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(stdout))
}
2022-11-03 23:42:42 +08:00
rows := strings.Split(string(stdout), "\r\n")
rowMap := make(map[string]string)
for _, v := range rows {
itemRow := strings.Split(v, "\n")
if len(itemRow) == 3 {
rowMap[itemRow[0]] = itemRow[1]
2022-10-31 17:26:15 +08:00
}
}
2022-11-03 23:42:42 +08:00
var info dto.RedisStatus
arr, err := json.Marshal(rowMap)
if err != nil {
fmt.Println(err)
2022-10-31 17:26:15 +08:00
}
2022-11-03 23:42:42 +08:00
_ = json.Unmarshal(arr, &info)
fmt.Println(info)
}