Skip to content

Commit

Permalink
feat: support Elastic Cache Redis & RedisLabs for selecting dbs
Browse files Browse the repository at this point in the history
Closes: #16, #33, #50
  • Loading branch information
luin committed Dec 3, 2016
1 parent 330f52f commit 55c6f14
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions client/components/main/Main/Database/KeyBrowser/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Footer extends React.Component {

componentDidMount() {
this.updateInfo();
this.updateDBCount();
this.interval = setInterval(this.updateInfo.bind(this), 10000);
}

Expand All @@ -19,6 +20,25 @@ class Footer extends React.Component {
}
}

updateDBCount() {
this.props.redis.config('get', 'databases', (err, res) => {
if (!err) {
if (res[1]) {
this.setState({ databases: Number(res[1]) });
} else {
const redis = this.props.redis.duplicate();
const select = redis.select.bind(redis);
this.guessDatabaseNumber(select, 15).then((count) => {
console.log('===', count)
return typeof count === 'number' ? count : this.guessDatabaseNumber(select, 1, 0);
}).then((count) => {
this.setState({ databases: count + 1 });
});
}
}
});
}

updateInfo() {
this.props.redis.info((err, res) => {
if (err) {
Expand All @@ -36,12 +56,21 @@ class Footer extends React.Component {

this.setState(info);
});
}

this.props.redis.config('get', 'databases', (err, res) => {
if (res && res[1]) {
this.setState({ databases: Number(res[1]) });
guessDatabaseNumber(select, startIndex, lastSuccessIndex) {
if (startIndex > 30) {
return Promise.resolve(30);
}
return select(startIndex)
.then(() => {
return this.guessDatabaseNumber(select, startIndex + 1, startIndex);
}).catch((err) => {
if (typeof lastSuccessIndex === 'number') {
return lastSuccessIndex;
}
});
return null;
})
}

componentWillUnmount() {
Expand Down Expand Up @@ -87,7 +116,7 @@ class Footer extends React.Component {
>{i}</option>);
}
return items;
})(this.state.databases)
})(this.state.databases || 1)
}
</select>
</div>
Expand Down

0 comments on commit 55c6f14

Please sign in to comment.