perf: support unix-socket via url string #142

This commit is contained in:
Lykin 2024-02-18 14:27:21 +08:00
parent a2331675d7
commit 09264134ec
2 changed files with 17 additions and 5 deletions

View File

@ -536,18 +536,28 @@ func (c *connectionService) ParseConnectURL(url string) (resp types.JSResp) {
return return
} }
var network, addr string
var port int
if urlOpt.Network == "unix" {
network = urlOpt.Network
addr = urlOpt.Addr
} else {
network = "tcp"
addrPart := strings.Split(urlOpt.Addr, ":") addrPart := strings.Split(urlOpt.Addr, ":")
addr := addrPart[0] addr = addrPart[0]
port := 6379 port = 6379
if len(addrPart) > 1 { if len(addrPart) > 1 {
port, _ = strconv.Atoi(addrPart[1]) port, _ = strconv.Atoi(addrPart[1])
} }
}
var sslServerName string var sslServerName string
if urlOpt.TLSConfig != nil { if urlOpt.TLSConfig != nil {
sslServerName = urlOpt.TLSConfig.ServerName sslServerName = urlOpt.TLSConfig.ServerName
} }
resp.Success = true resp.Success = true
resp.Data = struct { resp.Data = struct {
Network string `json:"network"`
Sock string `json:"sock"`
Addr string `json:"addr"` Addr string `json:"addr"`
Port int `json:"port"` Port int `json:"port"`
Username string `json:"username"` Username string `json:"username"`
@ -556,6 +566,7 @@ func (c *connectionService) ParseConnectURL(url string) (resp types.JSResp) {
ExecTimeout int64 `json:"execTimeout"` ExecTimeout int64 `json:"execTimeout"`
SSLServerName string `json:"sslServerName,omitempty"` SSLServerName string `json:"sslServerName,omitempty"`
}{ }{
Network: network,
Addr: addr, Addr: addr,
Port: port, Port: port,
Username: urlOpt.Username, Username: urlOpt.Username,

View File

@ -278,6 +278,7 @@ const pasteFromClipboard = async () => {
$message.error(i18n.t('dialogue.connection.parse_fail', { reason: e.message })) $message.error(i18n.t('dialogue.connection.parse_fail', { reason: e.message }))
return return
} }
generalForm.value.network = opt.network || 'tcp'
generalForm.value.name = generalForm.value.addr = opt.addr generalForm.value.name = generalForm.value.addr = opt.addr
generalForm.value.port = opt.port generalForm.value.port = opt.port
generalForm.value.username = opt.username generalForm.value.username = opt.username