feat: Cluster mode support

- NewConnectionDialog: cluster checkbox
- connection.ts: use Redis.Cluster() when cluster is enabled
- i18n keys for cluster (zh-CN + en)
This commit is contained in:
2026-07-05 21:20:42 +08:00
parent e46d6a80be
commit 169017df65
6 changed files with 54 additions and 3 deletions
+37
View File
@@ -22,6 +22,7 @@ export interface ConnectionOptions {
sentinelPort?: number
sentinelMasterName?: string
sentinelNodePassword?: string
cluster?: boolean
sshEnabled?: boolean
sshHost?: string
sshPort?: number
@@ -210,6 +211,42 @@ export async function connect(id: string, opts: ConnectionOptions): Promise<void
return
}
if (opts.cluster) {
// Cluster mode
const clusterOptions: any = {
redisOptions: {
username: opts.username || undefined,
password: opts.password || undefined,
tls: opts.tls ? {
rejectUnauthorized: opts.tlsRejectUnauthorized || false,
checkServerIdentity: () => undefined,
} : undefined,
},
clusterRetryStrategy(times: number) {
if (times > 3) return null
return Math.min(times * 200, 1000)
},
enableReadyCheck: true,
}
const redis = new Redis.Cluster([{ host: opts.host, port: opts.port }], clusterOptions)
redis.once('ready', () => {
clients.set(id, { client: redis as any })
resolve()
})
redis.once('error', (err: Error) => {
redis.disconnect()
reject(err)
})
setTimeout(() => {
if (!clients.has(id)) {
redis.disconnect()
reject(new Error('连接超时,请检查主机和端口'))
}
}, 12000)
return
}
if (opts.sshEnabled) {
const tunnel = await createSshTunnel(opts)
sshClient = tunnel.sshClient