Browse Source

feat: 数据库支持多 Redis 切换 (#5001)

Refs #3927
pull/5014/head
ssongliu 6 months ago committed by GitHub
parent
commit
c56435970a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      backend/app/api/v1/backup.go
  2. 50
      backend/app/api/v1/database_redis.go
  3. 16
      backend/app/api/v1/terminal.go
  4. 16
      backend/app/dto/database.go
  5. 2
      backend/app/service/backup.go
  6. 7
      backend/app/service/backup_redis.go
  7. 68
      backend/app/service/database_redis.go
  8. 7
      backend/router/ro_database.go
  9. 172
      cmd/server/docs/docs.go
  10. 172
      cmd/server/docs/swagger.json
  11. 114
      cmd/server/docs/swagger.yaml
  12. 16
      frontend/src/api/interface/database.ts
  13. 22
      frontend/src/api/modules/database.ts
  14. 3
      frontend/src/components/app-status/index.vue
  15. 12
      frontend/src/components/terminal/index.vue
  16. 213
      frontend/src/views/database/redis/index.vue
  17. 29
      frontend/src/views/database/redis/password/index.vue
  18. 17
      frontend/src/views/database/redis/setting/index.vue
  19. 12
      frontend/src/views/database/redis/setting/persistence/index.vue
  20. 5
      frontend/src/views/database/redis/setting/status/index.vue
  21. 4
      frontend/src/views/host/terminal/command/index.vue

2
backend/app/api/v1/backup.go

@ -343,7 +343,7 @@ func (b *BaseApi) Backup(c *gin.Context) {
return
}
case "redis":
if err := backupService.RedisBackup(); err != nil {
if err := backupService.RedisBackup(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}

50
backend/app/api/v1/database_redis.go

@ -12,11 +12,17 @@ import (
// @Tags Database Redis
// @Summary Load redis status info
// @Description 获取 redis 状态信息
// @Accept json
// @Param request body dto.OperationWithName true "request"
// @Success 200 {object} dto.RedisStatus
// @Security ApiKeyAuth
// @Router /databases/redis/status [get]
func (b *BaseApi) LoadRedisStatus(c *gin.Context) {
data, err := redisService.LoadStatus()
var req dto.OperationWithName
if err := helper.CheckBind(&req, c); err != nil {
return
}
data, err := redisService.LoadStatus(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
@ -28,11 +34,17 @@ func (b *BaseApi) LoadRedisStatus(c *gin.Context) {
// @Tags Database Redis
// @Summary Load redis conf
// @Description 获取 redis 配置信息
// @Accept json
// @Param request body dto.OperationWithName true "request"
// @Success 200 {object} dto.RedisConf
// @Security ApiKeyAuth
// @Router /databases/redis/conf [get]
func (b *BaseApi) LoadRedisConf(c *gin.Context) {
data, err := redisService.LoadConf()
var req dto.OperationWithName
if err := helper.CheckBind(&req, c); err != nil {
return
}
data, err := redisService.LoadConf(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
@ -44,11 +56,17 @@ func (b *BaseApi) LoadRedisConf(c *gin.Context) {
// @Tags Database Redis
// @Summary Load redis persistence conf
// @Description 获取 redis 持久化配置
// @Accept json
// @Param request body dto.OperationWithName true "request"
// @Success 200 {object} dto.RedisPersistence
// @Security ApiKeyAuth
// @Router /databases/redis/persistence/conf [get]
func (b *BaseApi) LoadPersistenceConf(c *gin.Context) {
data, err := redisService.LoadPersistenceConf()
var req dto.OperationWithName
if err := helper.CheckBind(&req, c); err != nil {
return
}
data, err := redisService.LoadPersistenceConf(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
@ -131,29 +149,3 @@ func (b *BaseApi) UpdateRedisPersistenceConf(c *gin.Context) {
}
helper.SuccessWithData(c, nil)
}
// @Tags Database Redis
// @Summary Page redis backups
// @Description 获取 redis 备份记录分页
// @Accept json
// @Param request body dto.PageInfo true "request"
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /databases/redis/backup/search [post]
func (b *BaseApi) RedisBackupList(c *gin.Context) {
var req dto.PageInfo
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
total, list, err := redisService.SearchBackupListWithPage(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
}

16
backend/app/api/v1/terminal.go

@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/copier"
@ -86,23 +87,24 @@ func (b *BaseApi) RedisWsSsh(c *gin.Context) {
if wshandleError(wsConn, errors.WithMessage(err, "invalid param rows in request")) {
return
}
redisConf, err := redisService.LoadConf()
if wshandleError(wsConn, errors.WithMessage(err, "load redis container failed")) {
name := c.Query("name")
redisInfo, err := appInstallService.LoadConnInfo(dto.OperationWithNameAndType{Type: "redis", Name: name})
if wshandleError(wsConn, errors.WithMessage(err, "invalid param rows in request")) {
return
}
defer wsConn.Close()
commands := []string{"redis-cli"}
if len(redisConf.Requirepass) != 0 {
commands = []string{"redis-cli", "-a", redisConf.Requirepass, "--no-auth-warning"}
if len(redisInfo.Password) != 0 {
commands = []string{"redis-cli", "-a", redisInfo.Password, "--no-auth-warning"}
}
pidMap := loadMapFromDockerTop(redisConf.ContainerName)
itemCmds := append([]string{"exec", "-it", redisConf.ContainerName}, commands...)
pidMap := loadMapFromDockerTop(redisInfo.Password)
itemCmds := append([]string{"exec", "-it", redisInfo.ContainerName}, commands...)
slave, err := terminal.NewCommand(itemCmds)
if wshandleError(wsConn, err) {
return
}
defer killBash(redisConf.ContainerName, strings.Join(commands, " "), pidMap)
defer killBash(redisInfo.ContainerName, strings.Join(commands, " "), pidMap)
defer slave.Close()
tty, err := terminal.NewLocalWsSession(cols, rows, wsConn, slave, false)

16
backend/app/dto/database.go

@ -131,7 +131,7 @@ type MysqlStatus struct {
}
type MysqlVariables struct {
BinlogCacheSize string `json:"binlog_cache_size"`
BinlogCacheSize string `json:"binlog_cache_size"`
InnodbBufferPoolSize string `json:"innodb_buffer_pool_size"`
InnodbLogBufferSize string `json:"innodb_log_buffer_size"`
JoinBufferSize string `json:"join_buffer_size"`
@ -165,26 +165,26 @@ type MysqlVariablesUpdateHelper struct {
// redis
type ChangeRedisPass struct {
Value string `json:"value" validate:"required"`
Database string `json:"database" validate:"required"`
Value string `json:"value" validate:"required"`
}
type RedisConfUpdate struct {
Database string `json:"database" validate:"required"`
Timeout string `json:"timeout"`
Maxclients string `json:"maxclients"`
Maxmemory string `json:"maxmemory"`
}
type RedisConfPersistenceUpdate struct {
Database string `json:"database" validate:"required"`
Type string `json:"type" validate:"required,oneof=aof rbd"`
Appendonly string `json:"appendonly"`
Appendfsync string `json:"appendfsync"`
Save string `json:"save"`
}
type RedisConfUpdateByFile struct {
File string `json:"file" validate:"required"`
RestartNow bool `json:"restartNow"`
}
type RedisConf struct {
Database string `json:"database" validate:"required"`
Name string `json:"name"`
Port int64 `json:"port"`
ContainerName string `json:"containerName"`
@ -195,12 +195,14 @@ type RedisConf struct {
}
type RedisPersistence struct {
Database string `json:"database" validate:"required"`
Appendonly string `json:"appendonly"`
Appendfsync string `json:"appendfsync"`
Save string `json:"save"`
}
type RedisStatus struct {
Database string `json:"database" validate:"required"`
TcpPort string `json:"tcp_port"`
UptimeInDays string `json:"uptime_in_days"`
ConnectedClients string `json:"connected_clients"`
@ -217,12 +219,14 @@ type RedisStatus struct {
}
type DatabaseFileRecords struct {
Database string `json:"database" validate:"required"`
FileName string `json:"fileName"`
FileDir string `json:"fileDir"`
CreatedAt string `json:"createdAt"`
Size int `json:"size"`
}
type RedisBackupRecover struct {
Database string `json:"database" validate:"required"`
FileName string `json:"fileName"`
FileDir string `json:"fileDir"`
}

2
backend/app/service/backup.go

@ -49,7 +49,7 @@ type IBackupService interface {
MysqlRecoverByUpload(req dto.CommonRecover) error
PostgresqlRecoverByUpload(req dto.CommonRecover) error
RedisBackup() error
RedisBackup(db dto.CommonBackup) error
RedisRecover(db dto.CommonRecover) error
WebsiteBackup(db dto.CommonBackup) error

7
backend/app/service/backup_redis.go

@ -20,12 +20,12 @@ import (
"github.com/pkg/errors"
)
func (u *BackupService) RedisBackup() error {
func (u *BackupService) RedisBackup(db dto.CommonBackup) error {
localDir, err := loadLocalDir()
if err != nil {
return err
}
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", db.Name)
if err != nil {
return err
}
@ -51,6 +51,7 @@ func (u *BackupService) RedisBackup() error {
}
record := &model.BackupRecord{
Type: "redis",
Name: db.Name,
Source: "LOCAL",
BackupType: "LOCAL",
FileDir: itemDir,
@ -64,7 +65,7 @@ func (u *BackupService) RedisBackup() error {
}
func (u *BackupService) RedisRecover(req dto.CommonRecover) error {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", req.Name)
if err != nil {
return err
}

68
backend/app/service/database_redis.go

@ -6,8 +6,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"github.com/1Panel-dev/1Panel/backend/app/dto"
@ -23,11 +21,9 @@ type IRedisService interface {
UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate) error
ChangePassword(info dto.ChangeRedisPass) error
LoadStatus() (*dto.RedisStatus, error)
LoadConf() (*dto.RedisConf, error)
LoadPersistenceConf() (*dto.RedisPersistence, error)
SearchBackupListWithPage(req dto.PageInfo) (int64, interface{}, error)
LoadStatus(req dto.OperationWithName) (*dto.RedisStatus, error)
LoadConf(req dto.OperationWithName) (*dto.RedisConf, error)
LoadPersistenceConf(req dto.OperationWithName) (*dto.RedisPersistence, error)
}
func NewIRedisService() IRedisService {
@ -35,7 +31,7 @@ func NewIRedisService() IRedisService {
}
func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", req.Database)
if err != nil {
return err
}
@ -55,7 +51,7 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error {
}
func (u *RedisService) ChangePassword(req dto.ChangeRedisPass) error {
if err := updateInstallInfoInDB("redis", "", "password", req.Value); err != nil {
if err := updateInstallInfoInDB("redis", req.Database, "password", req.Value); err != nil {
return err
}
if err := updateInstallInfoInDB("redis-commander", "", "password", req.Value); err != nil {
@ -66,7 +62,7 @@ func (u *RedisService) ChangePassword(req dto.ChangeRedisPass) error {
}
func (u *RedisService) UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate) error {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", req.Database)
if err != nil {
return err
}
@ -88,8 +84,8 @@ func (u *RedisService) UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate)
return nil
}
func (u *RedisService) LoadStatus() (*dto.RedisStatus, error) {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
func (u *RedisService) LoadStatus(req dto.OperationWithName) (*dto.RedisStatus, error) {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", req.Name)
if err != nil {
return nil, err
}
@ -116,8 +112,8 @@ func (u *RedisService) LoadStatus() (*dto.RedisStatus, error) {
return &info, nil
}
func (u *RedisService) LoadConf() (*dto.RedisConf, error) {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
func (u *RedisService) LoadConf(req dto.OperationWithName) (*dto.RedisConf, error) {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", req.Name)
if err != nil {
return nil, err
}
@ -133,8 +129,8 @@ func (u *RedisService) LoadConf() (*dto.RedisConf, error) {
return &item, nil
}
func (u *RedisService) LoadPersistenceConf() (*dto.RedisPersistence, error) {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
func (u *RedisService) LoadPersistenceConf(req dto.OperationWithName) (*dto.RedisPersistence, error) {
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", req.Name)
if err != nil {
return nil, err
}
@ -151,46 +147,6 @@ func (u *RedisService) LoadPersistenceConf() (*dto.RedisPersistence, error) {
return &item, nil
}
func (u *RedisService) SearchBackupListWithPage(req dto.PageInfo) (int64, interface{}, error) {
var (
list []dto.DatabaseFileRecords
backDatas []dto.DatabaseFileRecords
)
redisInfo, err := appInstallRepo.LoadBaseInfo("redis", "")
if err != nil {
return 0, nil, err
}
localDir, err := loadLocalDir()
if err != nil {
return 0, nil, err
}
backupDir := path.Join(localDir, fmt.Sprintf("database/redis/%s", redisInfo.Name))
_ = filepath.Walk(backupDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if !info.IsDir() {
list = append(list, dto.DatabaseFileRecords{
CreatedAt: info.ModTime().Format("2006-01-02 15:04:05"),
Size: int(info.Size()),
FileDir: backupDir,
FileName: info.Name(),
})
}
return nil
})
total, start, end := len(list), (req.Page-1)*req.PageSize, req.Page*req.PageSize
if start > total {
backDatas = make([]dto.DatabaseFileRecords, 0)
} else {
if end >= total {
end = total
}
backDatas = list[start:end]
}
return int64(total), backDatas, nil
}
func configGetStr(containerName, password, param string) (string, error) {
commands := append(redisExec(containerName, password), []string{"config", "get", param}...)
cmd := exec.Command("docker", commands...)

7
backend/router/ro_database.go

@ -35,12 +35,11 @@ func (s *DatabaseRouter) InitRouter(Router *gin.RouterGroup) {
cmdRouter.POST("/remote", baseApi.LoadRemoteAccess)
cmdRouter.GET("/options", baseApi.ListDBName)
cmdRouter.GET("/redis/persistence/conf", baseApi.LoadPersistenceConf)
cmdRouter.GET("/redis/status", baseApi.LoadRedisStatus)
cmdRouter.GET("/redis/conf", baseApi.LoadRedisConf)
cmdRouter.POST("/redis/persistence/conf", baseApi.LoadPersistenceConf)
cmdRouter.POST("/redis/status", baseApi.LoadRedisStatus)
cmdRouter.POST("/redis/conf", baseApi.LoadRedisConf)
cmdRouter.GET("/redis/exec", baseApi.RedisWsSsh)
cmdRouter.POST("/redis/password", baseApi.ChangeRedisPassword)
cmdRouter.POST("/redis/backup/search", baseApi.RedisBackupList)
cmdRouter.POST("/redis/conf/update", baseApi.UpdateRedisConf)
cmdRouter.POST("/redis/persistence/update", baseApi.UpdateRedisPersistenceConf)

172
cmd/server/docs/docs.go

@ -5109,21 +5109,21 @@ const docTemplate = `{
}
}
},
"/databases/redis/backup/search": {
"post": {
"/databases/redis/conf": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取 redis 备份记录分页",
"description": "获取 redis 配置信息",
"consumes": [
"application/json"
],
"tags": [
"Database Redis"
],
"summary": "Page redis backups",
"summary": "Load redis conf",
"parameters": [
{
"description": "request",
@ -5131,32 +5131,10 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.PageInfo"
"$ref": "#/definitions/dto.OperationWithName"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.PageResult"
}
}
}
}
},
"/databases/redis/conf": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取 redis 配置信息",
"tags": [
"Database Redis"
],
"summary": "Load redis conf",
"responses": {
"200": {
"description": "OK",
@ -5255,10 +5233,24 @@ const docTemplate = `{
}
],
"description": "获取 redis 持久化配置",
"consumes": [
"application/json"
],
"tags": [
"Database Redis"
],
"summary": "Load redis persistence conf",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OperationWithName"
}
}
],
"responses": {
"200": {
"description": "OK",
@ -5317,10 +5309,24 @@ const docTemplate = `{
}
],
"description": "获取 redis 状态信息",
"consumes": [
"application/json"
],
"tags": [
"Database Redis"
],
"summary": "Load redis status info",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OperationWithName"
}
}
],
"responses": {
"200": {
"description": "OK",
@ -14323,9 +14329,13 @@ const docTemplate = `{
"dto.ChangeRedisPass": {
"type": "object",
"required": [
"database",
"value"
],
"properties": {
"database": {
"type": "string"
},
"value": {
"type": "string"
}
@ -14761,7 +14771,8 @@ const docTemplate = `{
"container",
"image",
"volume",
"network"
"network",
"buildcache"
]
},
"withTagAll": {
@ -17296,10 +17307,16 @@ const docTemplate = `{
},
"dto.RedisConf": {
"type": "object",
"required": [
"database"
],
"properties": {
"containerName": {
"type": "string"
},
"database": {
"type": "string"
},
"maxclients": {
"type": "string"
},
@ -17323,6 +17340,7 @@ const docTemplate = `{
"dto.RedisConfPersistenceUpdate": {
"type": "object",
"required": [
"database",
"type"
],
"properties": {
@ -17332,6 +17350,9 @@ const docTemplate = `{
"appendonly": {
"type": "string"
},
"database": {
"type": "string"
},
"save": {
"type": "string"
},
@ -17346,7 +17367,13 @@ const docTemplate = `{
},
"dto.RedisConfUpdate": {
"type": "object",
"required": [
"database"
],
"properties": {
"database": {
"type": "string"
},
"maxclients": {
"type": "string"
},
@ -17360,6 +17387,9 @@ const docTemplate = `{
},
"dto.RedisPersistence": {
"type": "object",
"required": [
"database"
],
"properties": {
"appendfsync": {
"type": "string"
@ -17367,6 +17397,9 @@ const docTemplate = `{
"appendonly": {
"type": "string"
},
"database": {
"type": "string"
},
"save": {
"type": "string"
}
@ -17374,10 +17407,16 @@ const docTemplate = `{
},
"dto.RedisStatus": {
"type": "object",
"required": [
"database"
],
"properties": {
"connected_clients": {
"type": "string"
},
"database": {
"type": "string"
},
"instantaneous_ops_per_sec": {
"type": "string"
},
@ -18578,6 +18617,9 @@ const docTemplate = `{
"dir": {
"type": "string"
},
"disableCNAME": {
"type": "boolean"
},
"dnsAccount": {
"$ref": "#/definitions/model.WebsiteDnsAccount"
},
@ -18599,6 +18641,12 @@ const docTemplate = `{
"message": {
"type": "string"
},
"nameserver1": {
"type": "string"
},
"nameserver2": {
"type": "string"
},
"organization": {
"type": "string"
},
@ -18617,6 +18665,9 @@ const docTemplate = `{
"pushDir": {
"type": "boolean"
},
"skipDNS": {
"type": "boolean"
},
"startDate": {
"type": "string"
},
@ -20542,7 +20593,6 @@ const docTemplate = `{
"required": [
"id",
"match",
"modifier",
"name",
"operate",
"proxyHost",
@ -20627,7 +20677,13 @@ const docTemplate = `{
"ID": {
"type": "integer"
},
"SkipDNSCheck": {
"nameservers": {
"type": "array",
"items": {
"type": "string"
}
},
"skipDNSCheck": {
"type": "boolean"
}
}
@ -20655,6 +20711,9 @@ const docTemplate = `{
"dir": {
"type": "string"
},
"disableCNAME": {
"type": "boolean"
},
"dnsAccountId": {
"type": "integer"
},
@ -20664,6 +20723,12 @@ const docTemplate = `{
"keyType": {
"type": "string"
},
"nameserver1": {
"type": "string"
},
"nameserver2": {
"type": "string"
},
"otherDomains": {
"type": "string"
},
@ -20675,6 +20740,9 @@ const docTemplate = `{
},
"pushDir": {
"type": "boolean"
},
"skipDNS": {
"type": "boolean"
}
}
},
@ -20699,17 +20767,59 @@ const docTemplate = `{
"request.WebsiteSSLUpdate": {
"type": "object",
"required": [
"id"
"acmeAccountId",
"id",
"primaryDomain",
"provider"
],
"properties": {
"acmeAccountId": {
"type": "integer"
},
"apply": {
"type": "boolean"
},
"autoRenew": {
"type": "boolean"
},
"description": {
"type": "string"
},
"dir": {
"type": "string"
},
"disableCNAME": {
"type": "boolean"
},
"dnsAccountId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"keyType": {
"type": "string"
},
"nameserver1": {
"type": "string"
},
"nameserver2": {
"type": "string"
},
"otherDomains": {
"type": "string"
},
"primaryDomain": {
"type": "string"
},
"provider": {
"type": "string"
},
"pushDir": {
"type": "boolean"
},
"skipDNS": {
"type": "boolean"
}
}
},

172
cmd/server/docs/swagger.json

@ -5102,21 +5102,21 @@
}
}
},
"/databases/redis/backup/search": {
"post": {
"/databases/redis/conf": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取 redis 备份记录分页",
"description": "获取 redis 配置信息",
"consumes": [
"application/json"
],
"tags": [
"Database Redis"
],
"summary": "Page redis backups",
"summary": "Load redis conf",
"parameters": [
{
"description": "request",
@ -5124,32 +5124,10 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.PageInfo"
"$ref": "#/definitions/dto.OperationWithName"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.PageResult"
}
}
}
}
},
"/databases/redis/conf": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取 redis 配置信息",
"tags": [
"Database Redis"
],
"summary": "Load redis conf",
"responses": {
"200": {
"description": "OK",
@ -5248,10 +5226,24 @@
}
],
"description": "获取 redis 持久化配置",
"consumes": [
"application/json"
],
"tags": [
"Database Redis"
],
"summary": "Load redis persistence conf",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OperationWithName"
}
}
],
"responses": {
"200": {
"description": "OK",
@ -5310,10 +5302,24 @@
}
],
"description": "获取 redis 状态信息",
"consumes": [
"application/json"
],
"tags": [
"Database Redis"
],
"summary": "Load redis status info",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OperationWithName"
}
}
],
"responses": {
"200": {
"description": "OK",
@ -14316,9 +14322,13 @@
"dto.ChangeRedisPass": {
"type": "object",
"required": [
"database",
"value"
],
"properties": {
"database": {
"type": "string"
},
"value": {
"type": "string"
}
@ -14754,7 +14764,8 @@
"container",
"image",
"volume",
"network"
"network",
"buildcache"
]
},
"withTagAll": {
@ -17289,10 +17300,16 @@
},
"dto.RedisConf": {
"type": "object",
"required": [
"database"
],
"properties": {
"containerName": {
"type": "string"
},
"database": {
"type": "string"
},
"maxclients": {
"type": "string"
},
@ -17316,6 +17333,7 @@
"dto.RedisConfPersistenceUpdate": {
"type": "object",
"required": [
"database",
"type"
],
"properties": {
@ -17325,6 +17343,9 @@
"appendonly": {
"type": "string"
},
"database": {
"type": "string"
},
"save": {
"type": "string"
},
@ -17339,7 +17360,13 @@
},
"dto.RedisConfUpdate": {
"type": "object",
"required": [
"database"
],
"properties": {
"database": {
"type": "string"
},
"maxclients": {
"type": "string"
},
@ -17353,6 +17380,9 @@
},
"dto.RedisPersistence": {
"type": "object",
"required": [
"database"
],
"properties": {
"appendfsync": {
"type": "string"
@ -17360,6 +17390,9 @@
"appendonly": {
"type": "string"
},
"database": {
"type": "string"
},
"save": {
"type": "string"
}
@ -17367,10 +17400,16 @@
},
"dto.RedisStatus": {
"type": "object",
"required": [
"database"
],
"properties": {
"connected_clients": {
"type": "string"
},
"database": {
"type": "string"
},
"instantaneous_ops_per_sec": {
"type": "string"
},
@ -18571,6 +18610,9 @@
"dir": {
"type": "string"
},
"disableCNAME": {
"type": "boolean"
},
"dnsAccount": {
"$ref": "#/definitions/model.WebsiteDnsAccount"
},
@ -18592,6 +18634,12 @@
"message": {
"type": "string"
},
"nameserver1": {
"type": "string"
},
"nameserver2": {
"type": "string"
},
"organization": {
"type": "string"
},
@ -18610,6 +18658,9 @@
"pushDir": {
"type": "boolean"
},
"skipDNS": {
"type": "boolean"
},
"startDate": {
"type": "string"
},
@ -20535,7 +20586,6 @@
"required": [
"id",
"match",
"modifier",
"name",
"operate",
"proxyHost",
@ -20620,7 +20670,13 @@
"ID": {
"type": "integer"
},
"SkipDNSCheck": {
"nameservers": {
"type": "array",
"items": {
"type": "string"
}
},
"skipDNSCheck": {
"type": "boolean"
}
}
@ -20648,6 +20704,9 @@
"dir": {
"type": "string"
},
"disableCNAME": {
"type": "boolean"
},
"dnsAccountId": {
"type": "integer"
},
@ -20657,6 +20716,12 @@
"keyType": {
"type": "string"
},
"nameserver1": {
"type": "string"
},
"nameserver2": {
"type": "string"
},
"otherDomains": {
"type": "string"
},
@ -20668,6 +20733,9 @@
},
"pushDir": {
"type": "boolean"
},
"skipDNS": {
"type": "boolean"
}
}
},
@ -20692,17 +20760,59 @@
"request.WebsiteSSLUpdate": {
"type": "object",
"required": [
"id"
"acmeAccountId",
"id",
"primaryDomain",
"provider"
],
"properties": {
"acmeAccountId": {
"type": "integer"
},
"apply": {
"type": "boolean"
},
"autoRenew": {
"type": "boolean"
},
"description": {
"type": "string"
},
"dir": {
"type": "string"
},
"disableCNAME": {
"type": "boolean"
},
"dnsAccountId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"keyType": {
"type": "string"
},
"nameserver1": {
"type": "string"
},
"nameserver2": {
"type": "string"
},
"otherDomains": {
"type": "string"
},
"primaryDomain": {
"type": "string"
},
"provider": {
"type": "string"
},
"pushDir": {
"type": "boolean"
},
"skipDNS": {
"type": "boolean"
}
}
},

114
cmd/server/docs/swagger.yaml

@ -207,9 +207,12 @@ definitions:
type: object
dto.ChangeRedisPass:
properties:
database:
type: string
value:
type: string
required:
- database
- value
type: object
dto.Clean:
@ -506,6 +509,7 @@ definitions:
- image
- volume
- network
- buildcache
type: string
withTagAll:
type: boolean
@ -2225,6 +2229,8 @@ definitions:
properties:
containerName:
type: string
database:
type: string
maxclients:
type: string
maxmemory:
@ -2237,6 +2243,8 @@ definitions:
type: string
timeout:
type: string
required:
- database
type: object
dto.RedisConfPersistenceUpdate:
properties:
@ -2244,6 +2252,8 @@ definitions:
type: string
appendonly:
type: string
database:
type: string
save:
type: string
type:
@ -2252,16 +2262,21 @@ definitions:
- rbd
type: string
required:
- database
- type
type: object
dto.RedisConfUpdate:
properties:
database:
type: string
maxclients:
type: string
maxmemory:
type: string
timeout:
type: string
required:
- database
type: object
dto.RedisPersistence:
properties:
@ -2269,13 +2284,19 @@ definitions:
type: string
appendonly:
type: string
database:
type: string
save:
type: string
required:
- database
type: object
dto.RedisStatus:
properties:
connected_clients:
type: string
database:
type: string
instantaneous_ops_per_sec:
type: string
keyspace_hits:
@ -2300,6 +2321,8 @@ definitions:
type: string
used_memory_rss:
type: string
required:
- database
type: object
dto.ResourceLimit:
properties:
@ -3070,6 +3093,8 @@ definitions:
type: string
dir:
type: string
disableCNAME:
type: boolean
dnsAccount:
$ref: '#/definitions/model.WebsiteDnsAccount'
dnsAccountId:
@ -3084,6 +3109,10 @@ definitions:
type: string
message:
type: string
nameserver1:
type: string
nameserver2:
type: string
organization:
type: string
pem:
@ -3096,6 +3125,8 @@ definitions:
type: string
pushDir:
type: boolean
skipDNS:
type: boolean
startDate:
type: string
status:
@ -4422,7 +4453,6 @@ definitions:
required:
- id
- match
- modifier
- name
- operate
- proxyHost
@ -4446,7 +4476,11 @@ definitions:
properties:
ID:
type: integer
SkipDNSCheck:
nameservers:
items:
type: string
type: array
skipDNSCheck:
type: boolean
required:
- ID
@ -4463,12 +4497,18 @@ definitions:
type: string
dir:
type: string
disableCNAME:
type: boolean
dnsAccountId:
type: integer
id:
type: integer
keyType:
type: string
nameserver1:
type: string
nameserver2:
type: string
otherDomains:
type: string
primaryDomain:
@ -4477,6 +4517,8 @@ definitions:
type: string
pushDir:
type: boolean
skipDNS:
type: boolean
required:
- acmeAccountId
- primaryDomain
@ -4496,14 +4538,43 @@ definitions:
type: object
request.WebsiteSSLUpdate:
properties:
acmeAccountId:
type: integer
apply:
type: boolean
autoRenew:
type: boolean
description:
type: string
dir:
type: string
disableCNAME:
type: boolean
dnsAccountId:
type: integer
id:
type: integer
keyType:
type: string
nameserver1:
type: string
nameserver2:
type: string
otherDomains:
type: string
primaryDomain:
type: string
provider:
type: string
pushDir:
type: boolean
skipDNS:
type: boolean
required:
- acmeAccountId
- id
- primaryDomain
- provider
type: object
request.WebsiteSSLUpload:
properties:
@ -8277,31 +8348,18 @@ paths:
summary: Page postgresql databases
tags:
- Database Postgresql
/databases/redis/backup/search:
post:
/databases/redis/conf:
get:
consumes:
- application/json
description: 获取 redis 备份记录分页
description: 获取 redis 配置信息
parameters:
- description: request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dto.PageInfo'
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.PageResult'
security:
- ApiKeyAuth: []
summary: Page redis backups
tags:
- Database Redis
/databases/redis/conf:
get:
description: 获取 redis 配置信息
$ref: '#/definitions/dto.OperationWithName'
responses:
"200":
description: OK
@ -8366,7 +8424,16 @@ paths:
paramKeys: []
/databases/redis/persistence/conf:
get:
consumes:
- application/json
description: 获取 redis 持久化配置
parameters:
- description: request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dto.OperationWithName'
responses:
"200":
description: OK
@ -8405,7 +8472,16 @@ paths:
paramKeys: []
/databases/redis/status:
get:
consumes:
- application/json
description: 获取 redis 状态信息
parameters:
- description: request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dto.OperationWithName'
responses:
"200":
description: OK

16
frontend/src/api/interface/database.ts

@ -221,20 +221,18 @@ export namespace Database {
// redis
export interface RedisConfUpdate {
database: string;
timeout: string;
maxclients: string;
maxmemory: string;
}
export interface RedisConfPersistenceUpdate {
database: string;
type: string;
appendonly: string;
appendfsync: string;
save: string;
}
export interface RedisConfUpdateByFile {
file: string;
restartNow: boolean;
}
export interface RedisStatus {
tcp_port: string;
uptime_in_days: string;
@ -263,16 +261,6 @@ export namespace Database {
appendfsync: string;
save: string;
}
export interface FileRecord {
fileName: string;
fileDir: string;
createdAt: string;
size: string;
}
export interface RedisRecover {
fileName: string;
fileDir: string;
}
// remote
export interface DatabaseInfo {

22
frontend/src/api/modules/database.ts

@ -108,20 +108,20 @@ export const loadRemoteAccess = (type: string, database: string) => {
};
// redis
export const loadRedisStatus = () => {
return http.get<Database.RedisStatus>(`/databases/redis/status`);
export const loadRedisStatus = (database: string) => {
return http.post<Database.RedisStatus>(`/databases/redis/status`, { name: database });
};
export const loadRedisConf = () => {
return http.get<Database.RedisConf>(`/databases/redis/conf`);
export const loadRedisConf = (database: string) => {
return http.post<Database.RedisConf>(`/databases/redis/conf`, { name: database });
};
export const redisPersistenceConf = () => {
return http.get<Database.RedisPersistenceConf>(`/databases/redis/persistence/conf`);
export const redisPersistenceConf = (database: string) => {
return http.post<Database.RedisPersistenceConf>(`/databases/redis/persistence/conf`, { name: database });
};
export const changeRedisPassword = (value: string) => {
if (value) {
value = Base64.encode(value);
export const changeRedisPassword = (database: string, password: string) => {
if (password) {
password = Base64.encode(password);
}
return http.post(`/databases/redis/password`, { value: value });
return http.post(`/databases/redis/password`, { database: database, value: password });
};
export const updateRedisPersistenceConf = (params: Database.RedisConfPersistenceUpdate) => {
return http.post(`/databases/redis/persistence/update`, params);
@ -129,7 +129,7 @@ export const updateRedisPersistenceConf = (params: Database.RedisConfPersistence
export const updateRedisConf = (params: Database.RedisConfUpdate) => {
return http.post(`/databases/redis/conf/update`, params);
};
export const updateRedisConfByFile = (params: Database.RedisConfUpdateByFile) => {
export const updateRedisConfByFile = (params: Database.DBConfUpdate) => {
return http.post(`/databases/redis/conffile/update`, params);
};

3
frontend/src/components/app-status/index.vue

@ -167,7 +167,7 @@ let refresh = ref(1);
const httpPort = ref(0);
const httpsPort = ref(0);
const em = defineEmits(['setting', 'isExist', 'before', 'update:loading', 'update:maskShow']);
const em = defineEmits(['setting', 'isExist', 'before', 'after', 'update:loading', 'update:maskShow']);
const setting = () => {
em('setting', false);
};
@ -227,6 +227,7 @@ const onOperate = async (operation: string) => {
em('update:loading', false);
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
onCheck();
em('after');
})
.catch(() => {
em('update:loading', false);

12
frontend/src/components/terminal/index.vue

@ -176,12 +176,14 @@ const onWSReceive = (message: MessageEvent) => {
switch (wsMsg.type) {
case 'cmd': {
term.value.element && term.value.focus();
let receiveMsg = Base64.decode(wsMsg.data);
if (initCmd.value != '') {
receiveMsg = receiveMsg.replace(initCmd.value.trim(), '').trim();
initCmd.value = '';
if (wsMsg.data) {
let receiveMsg = Base64.decode(wsMsg.data);
if (initCmd.value != '') {
receiveMsg = receiveMsg?.replace(initCmd.value.trim(), '').trim();
initCmd.value = '';
}
term.value.write(receiveMsg);
}
wsMsg.data && term.value.write(receiveMsg);
break;
}
case 'heartbeat': {

213
frontend/src/views/database/redis/index.vue

@ -1,16 +1,51 @@
<template>
<div v-loading="loading">
<LayoutContent :title="'Redis ' + $t('menu.database')">
<template #app>
<template #app v-if="currentDB?.from === 'local'">
<AppStatus
:app-key="'redis'"
:app-name="appName"
v-model:loading="loading"
v-model:mask-show="maskShow"
@before="onBefore"
@after="onAfter"
@setting="onSetting"
@is-exist="checkExist"
></AppStatus>
</template>
<template #search v-if="!isOnSetting && redisIsExist">
<el-select v-model="currentDBName" @change="changeDatabase()" class="p-w-200">
<template #prefix>{{ $t('commons.table.type') }}</template>
<el-option-group :label="$t('database.local')">
<div v-for="(item, index) in dbOptionsLocal" :key="index">
<el-option v-if="item.from === 'local'" :value="item.database" class="optionClass">
<span v-if="item.database.length < 25">{{ item.database }}</span>
<el-tooltip v-else :content="item.database" placement="top">
<span>{{ item.database.substring(0, 25) }}...</span>
</el-tooltip>
</el-option>
</div>
<el-button link type="primary" class="jumpAdd" @click="goRouter('app')" icon="Position">
{{ $t('database.goInstall') }}
</el-button>
</el-option-group>
<el-option-group :label="$t('database.remote')">
<div v-for="(item, index) in dbOptionsRemote" :key="index">
<el-option v-if="item.from === 'remote'" :value="item.database" class="optionClass">
<span v-if="item.database.length < 25">{{ item.database }}</span>
<el-tooltip v-else :content="item.database" placement="top">
<span>{{ item.database.substring(0, 25) }}...</span>
</el-tooltip>
<el-tag class="tagClass">
{{ item.type === 'mysql' ? 'MySQL' : 'MariaDB' }}
</el-tag>
</el-option>
</div>
<el-button link type="primary" class="jumpAdd" @click="goRouter('remote')" icon="Position">
{{ $t('database.createRemoteDB') }}
</el-button>
</el-option-group>
</el-select>
</template>
<template #toolbar v-if="!isOnSetting && redisIsExist">
<div :class="{ mask: redisStatus != 'Running' }">
<el-button type="primary" plain @click="onChangePassword">
@ -24,17 +59,18 @@
:style="{ height: `calc(100vh - ${loadHeight()})` }"
:key="isRefresh"
ref="terminalRef"
v-show="terminalShow"
v-show="terminalShow && redisStatus === 'Running'"
/>
<el-empty
v-if="redisStatus !== 'Running'"
:style="{ height: `calc(100vh - ${loadHeight()})`, 'background-color': '#000' }"
:description="$t('commons.service.serviceNotStarted', ['Redis'])"
></el-empty>
</template>
</LayoutContent>
<el-card v-if="redisStatus != 'Running' && !isOnSetting && redisIsExist && maskShow" class="mask-prompt">
<span>{{ $t('commons.service.serviceNotStarted', ['Redis']) }}</span>
</el-card>
<Setting ref="settingRef" style="margin-top: 30px" />
<Password ref="passwordRef" @check-exist="initTerminal" @close-terminal="closeTerminal(true)" />
<Password ref="passwordRef" @check-exist="reOpenTerminal" @close-terminal="closeTerminal(true)" />
<el-dialog
v-model="commandVisible"
:title="$t('app.checkTitle')"
@ -64,11 +100,12 @@ import Password from '@/views/database/redis/password/index.vue';
import Terminal from '@/components/terminal/index.vue';
import AppStatus from '@/components/app-status/index.vue';
import PortJumpDialog from '@/components/port-jump/index.vue';
import { nextTick, onBeforeUnmount, ref } from 'vue';
import { App } from '@/api/interface/app';
import { GetAppPort } from '@/api/modules/app';
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
import { CheckAppInstalled, GetAppPort } from '@/api/modules/app';
import router from '@/routers';
import { GlobalStore } from '@/store';
import { listDatabases } from '@/api/modules/database';
import { Database } from '@/api/interface/database';
const globalStore = GlobalStore();
const loading = ref(false);
@ -79,12 +116,18 @@ const settingRef = ref();
const isOnSetting = ref(false);
const redisIsExist = ref(false);
const redisStatus = ref();
const redisName = ref();
const terminalShow = ref(false);
const redisCommandPort = ref();
const commandVisible = ref(false);
const appKey = ref('redis');
const appName = ref();
const dbOptionsLocal = ref<Array<Database.DatabaseOption>>([]);
const dbOptionsRemote = ref<Array<Database.DatabaseOption>>([]);
const currentDB = ref<Database.DatabaseOption>();
const currentDBName = ref();
const dialogPortJumpRef = ref();
const isRefresh = ref();
@ -93,11 +136,11 @@ const onSetting = async () => {
isOnSetting.value = true;
terminalRef.value?.onClose(false);
terminalShow.value = false;
settingRef.value!.acceptParams({ status: redisStatus.value, redisName: redisName.value });
settingRef.value!.acceptParams({ status: redisStatus.value, database: currentDBName.value });
};
const loadHeight = () => {
return globalStore.openMenuTabs ? '400px' : '370px';
return globalStore.openMenuTabs ? '470px' : '440px';
};
const goDashboard = async () => {
@ -118,40 +161,104 @@ const loadDashboardPort = async () => {
const passwordRef = ref();
const onChangePassword = async () => {
passwordRef.value!.acceptParams();
passwordRef.value!.acceptParams({ database: currentDBName.value });
};
const checkExist = (data: App.CheckInstalled) => {
redisIsExist.value = data.isExist;
redisName.value = data.name;
redisStatus.value = data.status;
loading.value = false;
if (redisStatus.value === 'Running') {
loadDashboardPort();
nextTick(() => {
terminalShow.value = true;
terminalRef.value.acceptParams({
endpoint: '/api/v1/databases/redis/exec',
args: '',
error: '',
initCmd: '',
});
});
const goRouter = async (target: string) => {
if (target === 'app') {
router.push({ name: 'AppAll', query: { install: 'redis' } });
return;
}
router.push({ name: 'Redis-Remote' });
};
const changeDatabase = async () => {
for (const item of dbOptionsLocal.value) {
if (item.database == currentDBName.value) {
currentDB.value = item;
appKey.value = item.type;
appName.value = item.database;
reOpenTerminal();
return;
}
}
for (const item of dbOptionsRemote.value) {
if (item.database == currentDBName.value) {
currentDB.value = item;
break;
}
}
reOpenTerminal();
};
const loadDBOptions = async () => {
const res = await listDatabases('redis');
let datas = res.data || [];
dbOptionsLocal.value = [];
dbOptionsRemote.value = [];
currentDBName.value = globalStore.currentDB;
for (const item of datas) {
if (currentDBName.value && item.database === currentDBName.value) {
currentDB.value = item;
if (item.from === 'local') {
appKey.value = item.type;
appName.value = item.database;
}
}
if (item.from === 'local') {
dbOptionsLocal.value.push(item);
} else {
dbOptionsRemote.value.push(item);
}
}
if (currentDB.value) {
reOpenTerminal();
return;
}
if (dbOptionsLocal.value.length !== 0) {
currentDB.value = dbOptionsLocal.value[0];
currentDBName.value = dbOptionsLocal.value[0].database;
appKey.value = dbOptionsLocal.value[0].type;
appName.value = dbOptionsLocal.value[0].database;
}
if (!currentDB.value && dbOptionsRemote.value.length !== 0) {
currentDB.value = dbOptionsRemote.value[0];
currentDBName.value = dbOptionsRemote.value[0].database;
}
if (currentDB.value) {
reOpenTerminal();
}
};
const reOpenTerminal = async () => {
closeTerminal(false);
initTerminal();
};
const initTerminal = async () => {
if (redisStatus.value === 'Running') {
nextTick(() => {
terminalShow.value = true;
terminalRef.value.acceptParams({
endpoint: '/api/v1/databases/redis/exec',
args: '',
error: '',
initCmd: '',
loading.value = true;
await CheckAppInstalled('redis', currentDBName.value)
.then((res) => {
redisIsExist.value = res.data.isExist;
redisStatus.value = res.data.status;
loading.value = false;
nextTick(() => {
if (res.data.status === 'Running') {
terminalShow.value = true;
terminalRef.value.acceptParams({
endpoint: '/api/v1/databases/redis/exec',
args: `name=${currentDBName.value}`,
error: '',
initCmd: '',
});
}
});
isRefresh.value = !isRefresh.value;
})
.catch(() => {
closeTerminal(false);
loading.value = false;
});
}
};
const closeTerminal = async (isKeepShow: boolean) => {
isRefresh.value = !isRefresh.value;
@ -159,10 +266,34 @@ const closeTerminal = async (isKeepShow: boolean) => {
terminalShow.value = isKeepShow;
};
onMounted(() => {
loadDBOptions();
loadDashboardPort();
});
const onBefore = () => {
closeTerminal(true);
closeTerminal(false);
};
const onAfter = () => {
initTerminal();
};
onBeforeUnmount(() => {
closeTerminal(false);
});
</script>
<style lang="scss" scoped>
.jumpAdd {
margin-top: 10px;
margin-left: 15px;
margin-bottom: 5px;
font-size: 12px;
}
.tagClass {
float: right;
font-size: 12px;
margin-top: 5px;
}
.optionClass {
min-width: 350px;
}
</style>

29
frontend/src/views/database/redis/password/index.vue

@ -78,7 +78,7 @@
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { reactive, ref } from 'vue';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm } from 'element-plus';
@ -87,19 +87,16 @@ import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import { GetAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { App } from '@/api/interface/app';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
const loading = ref(false);
const dialogVisible = ref(false);
const form = ref<App.DatabaseConnInfo>({
username: '',
const form = reactive({
database: '',
password: '',
privilege: false,
containerName: '',
serviceName: '',
systemIP: '',
port: 0,
});
@ -111,8 +108,12 @@ const emit = defineEmits(['checkExist', 'closeTerminal']);
type FormInstance = InstanceType<typeof ElForm>;
const formRef = ref<FormInstance>();
const acceptParams = (): void => {
form.value.password = '';
interface DialogProps {
database: string;
}
const acceptParams = (params: DialogProps): void => {
form.database = params.database;
form.password = '';
loadPassword();
dialogVisible.value = true;
};
@ -121,20 +122,22 @@ const handleClose = () => {
};
const random = async () => {
form.value.password = getRandomStr(16);
form.password = getRandomStr(16);
};
const loadPassword = async () => {
const res = await GetAppConnInfo('redis', '');
const res = await GetAppConnInfo('redis', form.database);
form.containerName = res.data.containerName;
form.password = res.data.password;
form.port = res.data.port;
const settingInfoRes = await getSettingInfo();
form.value = res.data;
form.value.systemIP = settingInfoRes.data.systemIP || i18n.global.t('database.localIP');
form.systemIP = settingInfoRes.data.systemIP || i18n.global.t('database.localIP');
};
const onSubmit = async () => {
loading.value = true;
emit('closeTerminal');
await changeRedisPassword(form.value.password)
await changeRedisPassword(form.database, form.password)
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));

17
frontend/src/views/database/redis/setting/index.vue

@ -177,7 +177,7 @@ const persistenceRef = ref();
const useOld = ref(false);
const redisStatus = ref();
const redisName = ref();
const database = ref();
const formRef = ref<FormInstance>();
const redisConf = ref();
@ -186,7 +186,7 @@ const confirmDialogRef = ref();
const settingShow = ref<boolean>(false);
interface DialogProps {
redisName: string;
database: string;
status: string;
}
@ -197,14 +197,14 @@ const changeTab = (val: string) => {
loadConfFile();
break;
case 'persistence':
persistenceRef.value!.acceptParams({ status: redisStatus.value });
persistenceRef.value!.acceptParams({ status: redisStatus.value, database: database.value });
break;
case 'tuning':
case 'port':
loadform();
break;
case 'status':
statusRef.value!.acceptParams({ status: redisStatus.value });
statusRef.value!.acceptParams({ status: redisStatus.value, database: database.value });
break;
}
};
@ -215,7 +215,7 @@ const changeLoading = (status: boolean) => {
const acceptParams = (prop: DialogProps): void => {
redisStatus.value = prop.status;
redisName.value = prop.redisName;
database.value = prop.database;
settingShow.value = true;
loadConfFile();
};
@ -280,6 +280,7 @@ const onSubmitForm = async (formEl: FormInstance | undefined) => {
};
const submitForm = async () => {
let param = {
database: database.value,
timeout: form.timeout + '',
maxclients: form.maxclients + '',
maxmemory: form.maxmemory + 'mb',
@ -320,7 +321,7 @@ const onSaveFile = async () => {
const submitFile = async () => {
let param = {
type: 'redis',
database: redisName.value,
database: database.value,
file: redisConf.value,
};
loading.value = true;
@ -336,7 +337,7 @@ const submitFile = async () => {
};
const loadform = async () => {
const res = await loadRedisConf();
const res = await loadRedisConf(database.value);
form.name = res.data?.name;
form.timeout = Number(res.data?.timeout);
form.maxclients = Number(res.data?.maxclients);
@ -347,7 +348,7 @@ const loadform = async () => {
const loadConfFile = async () => {
useOld.value = false;
loading.value = true;
await loadDBFile('redis-conf', redisName.value)
await loadDBFile('redis-conf', database.value)
.then((res) => {
loading.value = false;
redisConf.value = res.data;

12
frontend/src/views/database/redis/setting/persistence/index.vue

@ -139,14 +139,17 @@ const rules = reactive({
appendfsync: [Rules.requiredSelect],
});
const formRef = ref<FormInstance>();
const database = ref();
const opRef = ref();
interface DialogProps {
database: string;
status: string;
}
const persistenceShow = ref(false);
const acceptParams = (prop: DialogProps): void => {
persistenceShow.value = true;
database.value = prop.database;
if (prop.status === 'Running') {
loadform();
search();
@ -179,7 +182,7 @@ const handleDelete = (index: number) => {
const search = async () => {
let params = {
type: 'redis',
name: '',
name: database.value,
detailName: '',
page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize,
@ -190,7 +193,7 @@ const search = async () => {
};
const onBackup = async () => {
emit('loading', true);
await handleBackup({ name: '', detailName: '', type: 'redis' })
await handleBackup({ name: database.value, detailName: '', type: 'redis' })
.then(() => {
emit('loading', false);
search();
@ -204,7 +207,7 @@ const onRecover = async () => {
let param = {
source: currentRow.value.source,
type: 'redis',
name: '',
name: database.value,
detailName: '',
file: currentRow.value.fileDir + '/' + currentRow.value.fileName,
};
@ -266,6 +269,7 @@ const buttons = [
const onSave = async (formEl: FormInstance | undefined, type: string) => {
let param = {} as Database.RedisConfPersistenceUpdate;
param.database = database.value;
if (type == 'aof') {
if (!formEl) return;
formEl.validate(async (valid) => {
@ -308,7 +312,7 @@ const onSave = async (formEl: FormInstance | undefined, type: string) => {
const loadform = async () => {
form.saves = [];
const res = await redisPersistenceConf();
const res = await redisPersistenceConf(database.value);
form.appendonly = res.data?.appendonly;
form.appendfsync = res.data?.appendfsync;
let itemSaves = res.data?.save.split(' ');

5
frontend/src/views/database/redis/setting/status/index.vue

@ -161,20 +161,23 @@ const redisStatus = reactive({
latest_fork_usec: '',
});
const database = ref();
const statusShow = ref(false);
interface DialogProps {
database: string;
status: string;
}
const acceptParams = (prop: DialogProps): void => {
statusShow.value = true;
database.value = prop.database;
if (prop.status === 'Running') {
loadStatus();
}
};
const loadStatus = async () => {
const res = await loadRedisStatus();
const res = await loadRedisStatus(database.value);
let hit = (
(Number(res.data.keyspace_hits) / (Number(res.data.keyspace_hits) + Number(res.data.keyspace_misses))) *
100

4
frontend/src/views/host/terminal/command/index.vue

@ -42,7 +42,7 @@
<el-table-column type="selection" fix />
<el-table-column
:label="$t('commons.table.name')"
show-overflow-tooltip=""
show-overflow-tooltip
min-width="100"
prop="name"
fix
@ -57,7 +57,7 @@
/>
<el-table-column
:label="$t('commons.table.group')"
show-overflow-tooltip=""
show-overflow-tooltip
min-width="100"
prop="groupBelong"
fix

Loading…
Cancel
Save