Skip to content

Commit

Permalink
feat: support quit cluster gracefully. Close #315
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 26, 2016
1 parent 0ac7eef commit fdb3d13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 10 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ the current connection.
var redis = new Redis();
redis.monitor(function (err, monitor) {
// Entering monitoring mode.
monitor.on('monitor', function (time, args) {
monitor.on('monitor', function (time, args, source, database) {
console.log(time + ": " + util.inspect(args));
});
});

// supports promise as well as other commands
redis.monitor().then(function (monitor) {
monitor.on('monitor', function (time, args) {
monitor.on('monitor', function (time, args, source, database) {
console.log(time + ": " + util.inspect(args));
});
});
Expand Down Expand Up @@ -218,6 +218,7 @@ Create a Redis instance
* [new Cluster(startupNodes, options)](#new_Cluster_new)
* [.connect()](#Cluster+connect) ⇒ <code>Promise</code>
* [.disconnect()](#Cluster+disconnect)
* [.quit()](#Cluster+quit) ⇒ <code>Promise</code>
* [.nodes([role])](#Cluster+nodes) ⇒ <code>[Array.&lt;Redis&gt;](#Redis)</code>
* [.getBuiltinCommands()](#Commander+getBuiltinCommands) ⇒ <code>Array.&lt;string&gt;</code>
* [.createBuiltinCommand(commandName)](#Commander+createBuiltinCommand) ⇒ <code>object</code>
Expand Down Expand Up @@ -256,6 +257,13 @@ Connect to a cluster
### cluster.disconnect()
Disconnect from every node in the cluster.

**Kind**: instance method of <code>[Cluster](#Cluster)</code>
**Access:** public
<a name="Cluster+quit"></a>

### cluster.quit() ⇒ <code>Promise</code>
Quit the cluster gracefully.

**Kind**: instance method of <code>[Cluster](#Cluster)</code>
**Access:** public
<a name="Cluster+nodes"></a>
Expand Down
22 changes: 22 additions & 0 deletions lib/cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,28 @@ Cluster.prototype.disconnect = function (reconnect) {
this.connectionPool.reset([]);
};

/**
* Quit the cluster gracefully.
*
* @return {Promise}
* @public
*/
Cluster.prototype.quit = function (callback) {
this.setStatus('disconnecting');

this.manuallyClosing = true;

if (this.reconnectTimeout) {
clearTimeout(this.reconnectTimeout);
this.reconnectTimeout = null;
}
return Promise.all(this.nodes().map(function (node) {
return node.quit();
})).then(function (res) {
return res.length;
}).nodeify(callback);
};

/**
* Get nodes with the specified role
*
Expand Down

0 comments on commit fdb3d13

Please sign in to comment.