feat: support connect by unix-socket #142
This commit is contained in:
parent
e1f022908c
commit
a2331675d7
|
@ -122,7 +122,6 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
|
|||
}
|
||||
|
||||
option := &redis.Options{
|
||||
Addr: fmt.Sprintf("%s:%d", config.Addr, config.Port),
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
DialTimeout: time.Duration(config.ConnTimeout) * time.Second,
|
||||
|
@ -130,6 +129,21 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
|
|||
WriteTimeout: time.Duration(config.ExecTimeout) * time.Second,
|
||||
TLSConfig: tlsConfig,
|
||||
}
|
||||
if config.Network == "unix" {
|
||||
option.Network = "unix"
|
||||
if len(config.Sock) <= 0 {
|
||||
option.Addr = "/tmp/redis.sock"
|
||||
} else {
|
||||
option.Addr = config.Sock
|
||||
}
|
||||
} else {
|
||||
option.Network = "tcp"
|
||||
if len(config.Addr) <= 0 {
|
||||
option.Addr = fmt.Sprintf("127.0.0.1:%d", config.Port)
|
||||
} else {
|
||||
option.Addr = fmt.Sprintf("%s:%d", config.Addr, config.Port)
|
||||
}
|
||||
}
|
||||
if config.LastDB > 0 {
|
||||
option.DB = config.LastDB
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ func (c *ConnectionsStorage) defaultConnections() types.Connections {
|
|||
func (c *ConnectionsStorage) defaultConnectionItem() types.ConnectionConfig {
|
||||
return types.ConnectionConfig{
|
||||
Name: "",
|
||||
Network: "tcp",
|
||||
Addr: "127.0.0.1",
|
||||
Port: 6379,
|
||||
Username: "",
|
||||
|
|
|
@ -6,6 +6,8 @@ type ConnectionConfig struct {
|
|||
Name string `json:"name" yaml:"name"`
|
||||
Group string `json:"group,omitempty" yaml:"-"`
|
||||
LastDB int `json:"lastDB" yaml:"last_db"`
|
||||
Network string `json:"network,omitempty" yaml:"network,omitempty"`
|
||||
Sock string `json:"sock,omitempty" yaml:"sock,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty"`
|
||||
|
|
|
@ -348,6 +348,20 @@ const pasteFromClipboard = async () => {
|
|||
:render-label="({ label, value }) => (value === '' ? $t(label) : label)" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :label="$t('dialogue.connection.addr')" :span="24" path="addr" required>
|
||||
<n-input-group>
|
||||
<n-select
|
||||
v-model:value="generalForm.network"
|
||||
:options="[
|
||||
{ value: 'tcp', label: 'TCP' },
|
||||
{ value: 'unix', label: 'UNIX' },
|
||||
]"
|
||||
style="max-width: 100px" />
|
||||
<template v-if="generalForm.network === 'unix'">
|
||||
<n-input
|
||||
v-model:value="generalForm.sock"
|
||||
:placeholder="$t('dialogue.connection.sock_tip')" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<n-input
|
||||
v-model:value="generalForm.addr"
|
||||
:placeholder="$t('dialogue.connection.addr_tip')" />
|
||||
|
@ -357,7 +371,10 @@ const pasteFromClipboard = async () => {
|
|||
:max="65535"
|
||||
:min="1"
|
||||
:show-button="false"
|
||||
placeholder="6379"
|
||||
style="width: 200px" />
|
||||
</template>
|
||||
</n-input-group>
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :label="$t('dialogue.connection.pwd')" :span="12" path="password">
|
||||
<n-input
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
"pwd": "Password",
|
||||
"name_tip": "Connection name",
|
||||
"addr_tip": "Redis server host",
|
||||
"sock_tip": "Redis server unix socket file",
|
||||
"usr_tip": "(Optional) Authentication username",
|
||||
"pwd_tip": "(Optional) Authentication password (Redis > 6.0)",
|
||||
"test": "Test Connection",
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
"pwd": "密码",
|
||||
"name_tip": "连接名",
|
||||
"addr_tip": "Redis服务地址",
|
||||
"sock_tip": "Redis套接字文件",
|
||||
"usr_tip": "(可选)Redis服务授权用户名",
|
||||
"pwd_tip": "(可选)Redis服务授权密码 (Redis > 6.0)",
|
||||
"test": "测试连接",
|
||||
|
|
|
@ -153,6 +153,8 @@ const useConnectionStore = defineStore('connections', {
|
|||
return {
|
||||
group: '',
|
||||
name: name || '',
|
||||
network: 'tcp',
|
||||
sock: '/tmp/redis.sock',
|
||||
addr: '127.0.0.1',
|
||||
port: 6379,
|
||||
username: '',
|
||||
|
|
Loading…
Reference in New Issue