From fa00487a476e82cbdbb1658dc5f700cd823ee506 Mon Sep 17 00:00:00 2001 From: qishibo Date: Thu, 16 Dec 2021 11:35:12 +0800 Subject: [PATCH] fix #735 ssh-sentinel connection bug --- src/components/ConnectionWrapper.vue | 10 ++++++---- src/components/Connections.vue | 2 ++ src/redisClient.js | 9 +++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/ConnectionWrapper.vue b/src/components/ConnectionWrapper.vue index eaf5cb7..183ba1b 100644 --- a/src/components/ConnectionWrapper.vue +++ b/src/components/ConnectionWrapper.vue @@ -138,18 +138,20 @@ export default { }, this.pingInterval); }, getRedisClient(config) { + // prevent changing back to raw config, such as config.db + const configCopy = JSON.parse(JSON.stringify(config)); // select db - config.db = this.lastSelectedDb; + configCopy.db = this.lastSelectedDb; // ssh client - if (config.sshOptions) { + if (configCopy.sshOptions) { var clientPromise = redisClient.createSSHConnection( - config.sshOptions, config.host, config.port, config.auth, config); + configCopy.sshOptions, configCopy.host, configCopy.port, configCopy.auth, configCopy); } // normal client else { var clientPromise = redisClient.createConnection( - config.host, config.port, config.auth, config); + configCopy.host, configCopy.port, configCopy.auth, configCopy); } clientPromise.then((client) => { diff --git a/src/components/Connections.vue b/src/components/Connections.vue index 27d7eb3..84e1f55 100644 --- a/src/components/Connections.vue +++ b/src/components/Connections.vue @@ -43,6 +43,8 @@ export default { for (const item of connections) { item.connectionName = storage.getConnectionName(item); + // fix history bug, prevent db into config + delete item.db; slovedConnections.push(item); } diff --git a/src/redisClient.js b/src/redisClient.js index 12b673f..3c11e3f 100644 --- a/src/redisClient.js +++ b/src/redisClient.js @@ -30,10 +30,14 @@ Redis.Command.setReplyTransformer("hgetall", (result) => { export default { - createConnection(host, port, auth, config, promise = true, forceStandalone = false) { + createConnection(host, port, auth, config, promise = true, forceStandalone = false, removeDb = false) { let options = this.getRedisOptions(host, port, auth, config); let client = null; + if (removeDb) { + delete options.db; + } + if (forceStandalone) { client = new Redis(options); } @@ -100,7 +104,8 @@ export default { // sentinel mode if (configRaw.sentinelOptions) { - let client = this.createConnection(listenAddress.address, listenAddress.port, auth, configRaw, false, true); + // this is a sentinel connection, remove db + let client = this.createConnection(listenAddress.address, listenAddress.port, auth, configRaw, false, true, true); client.on('ready', () => { client.call('sentinel', 'get-master-addr-by-name', configRaw.sentinelOptions.masterName).then(reply => {