Skip to content

Commit

Permalink
fix when connection failed
Browse files Browse the repository at this point in the history
  • Loading branch information
qishibo committed Mar 22, 2019
1 parent 030b112 commit 825cc7f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
39 changes: 29 additions & 10 deletions src/components/Connections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,43 @@ export default {
}

this.getDbIndex(menuIndex);
this.setGlobalConnection(menuIndex, connection);

// open status tab
if (!this.openedStatus[menuIndex]) {
this.$bus.$emit('openStatus');
this.openedStatus[menuIndex] = true;
const client = this.setGlobalConnection(menuIndex, connection);

// new connection, not ready
if (!client.ready) {
client.on('ready', () => {
// open status tab
if (!this.openedStatus[menuIndex]) {
this.$bus.$emit('openStatus', connection.showName);
this.openedStatus[menuIndex] = true;
}

this.refreshKeyList();
});
}

this.refreshKeyList();
// connection is ready
else{
this.refreshKeyList();
}
},
setGlobalConnection(menuIndex, connection) {
if (!this.connectionPool[menuIndex]) {
const client = redisClient.createConnection(connection.host, connection.port, connection.auth, menuIndex);
let client = this.connectionPool[menuIndex];

if (!client || !client.ready) {
client = redisClient.createConnection(connection.host, connection.port, connection.auth, menuIndex);

client.on('error', (err) => {
alert(err);
});

this.connectionPool[menuIndex] = client;
}

// set global client
this.$util.set('client', this.connectionPool[menuIndex]);
this.$util.set('client', client);

return client;
},
deleteConnection(connection) {
console.log(connection);
Expand Down
18 changes: 9 additions & 9 deletions src/components/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ export default {
});

// open status tab
this.$bus.$on('openStatus', () => {
console.log('open status');
this.$bus.$on('openStatus', (tabName) => {
console.log('open status', tabName);

const client = this.$util.get('client');
// const client = this.$util.get('client');

const { host } = client.options;
const { port } = client.options;
const newTabName = `${host}:${port}`;
// const { host } = client.options;
// const { port } = client.options;
// const newTabName = `${host}:${port}`;

this.tabs.push({
name: newTabName,
title: newTabName,
name: tabName,
title: tabName,
component_name: 'Status',
});

this.selectedTabName = newTabName;
this.selectedTabName = tabName;
});

// remove pre tab
Expand Down
6 changes: 1 addition & 5 deletions src/redisClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ export default {
},
menu_index: menuIndex,
};
const client = redis.createClient(port, host, options);

client.on('error', (err) => {
alert(err);
return false;
});
const client = redis.createClient(port, host, options);

return client;
},
Expand Down

0 comments on commit 825cc7f

Please sign in to comment.