fix #735 ssh-sentinel connection bug

This commit is contained in:
qishibo 2021-12-16 11:35:12 +08:00
parent 6e5073ba10
commit fa00487a47
3 changed files with 15 additions and 6 deletions

View File

@ -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) => {

View File

@ -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);
}

View File

@ -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 => {