Skip to content

Commit

Permalink
feat: support Elastic Cache Redis & RedisLabs for selecting database
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 18e5629
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
4 changes: 4 additions & 0 deletions client/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const actions = {

function handleRedis(config, override) {
dispatch({ type: 'updateConnectStatus', data: 'Redis connecting...' });
if (config.ssl) {
config.tls = {
}
}
const redis = new Redis(_.assign({}, config, override, {
showFriendlyErrorStack: true,
retryStrategy() {
Expand Down
6 changes: 5 additions & 1 deletion client/components/main/Main/ConnectionSelector/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Config extends React.Component {

handleChange(property, e) {
let value = e.target.value;
if (property === 'ssh') {
if (property === 'ssh' || property === 'ssl') {
value = e.target.checked;
}
this.setProp(property, value);
Expand Down Expand Up @@ -81,6 +81,10 @@ class Config extends React.Component {
<label htmlFor="password">Password:</label>
<input type="password" id="password" onChange={this.handleChange.bind(this, 'password')} value={this.getProp('password')} />
</div>
<div className="nt-form-row">
<label htmlFor="ssh">SSL:</label>
<input type="checkbox" id="ssl" onChange={this.handleChange.bind(this, 'ssl')} checked={this.getProp('ssl')} />
</div>
<div className="nt-form-row">
<label htmlFor="ssh">SSH Tunnel:</label>
<input type="checkbox" id="ssh" onChange={this.handleChange.bind(this, 'ssh')} checked={this.getProp('ssh')} />
Expand Down
4 changes: 2 additions & 2 deletions client/components/main/Main/ConnectionSelector/Config.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
}

.ssh-key {
height: 20px;
height: 19px;
line-height: 20px;
padding: 0;
text-align: center;
width: 30px;
position: relative;
top: -1px;
top: 0;
left: -30px;
border-top: 0;
border-bottom: 0;
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class KeyList extends React.Component {
if (this.state.scanning) {
return <span style={ { color: '#ccc' }}>Scanning...(cursor {this.state.cursor})</span>;
}
return <a href="#" onClick={(evt) => {
return <a href="#" style={ { color: '#666' } } onClick={(evt) => {
evt.preventDefault();
this.scan();
}}>Scan more</a>;
Expand Down
6 changes: 6 additions & 0 deletions server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ app.on('window-all-closed', function () {
}
});

app.on('activate', function (e, hasVisibleWindows) {
if (!hasVisibleWindows) {
windowManager.create();
}
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function () {
Expand Down

0 comments on commit 18e5629

Please sign in to comment.