diff --git a/API.md b/API.md index ca1897e6d..00162fdf2 100644 --- a/API.md +++ b/API.md @@ -56,6 +56,7 @@ Creates a Redis instance | [options.family] | string | 4 | Version of IP stack. Defaults to 4. | | [options.path] | string | null | Local domain socket path. If set the `port`, `host` and `family` will be ignored. | | [options.keepAlive] | number | 0 | TCP KeepAlive on the socket with a X ms delay before start. Set to a non-number value to disable keepAlive. | +| [options.noDelay] | boolean | true | Whether to disable the Nagle's Algorithm. By default we disable it to reduce the latency. | | [options.connectionName] | string | null | Connection name. | | [options.db] | number | 0 | Database index to use. | | [options.password] | string | null | If set, client will send AUTH command with the value of this option when connected. | @@ -99,7 +100,7 @@ This method will be invoked automatically when creating a new Redis instance. | Param | Type | | --- | --- | -| callback | function | +| callback | function | @@ -270,7 +271,7 @@ Quit the cluster gracefully. | Param | Type | | --- | --- | -| callback | function | +| callback | function | diff --git a/lib/redis.js b/lib/redis.js index a7374b0f5..6ac21d718 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -33,6 +33,8 @@ var commands = require('redis-commands'); * `host` and `family` will be ignored. * @param {number} [options.keepAlive=0] - TCP KeepAlive on the socket with a X ms delay before start. * Set to a non-number value to disable keepAlive. + * @param {boolean} [options.noDelay=true] - Whether to disable the Nagle's Algorithm. By default we disable + * it to reduce the latency. * @param {string} [options.connectionName=null] - Connection name. * @param {number} [options.db=0] - Database index to use. * @param {string} [options.password=null] - If set, client will send AUTH command @@ -153,6 +155,7 @@ Redis.defaultOptions = { return Math.min(times * 2, 2000); }, keepAlive: 0, + noDelay: true, connectionName: null, // Sentinel sentinels: null, @@ -288,6 +291,10 @@ Redis.prototype.connect = function (callback) { }); } + if (_this.options.noDelay) { + stream.setNoDelay(true); + } + var connectionConnectHandler = function () { _this.removeListener('close', connectionCloseHandler); resolve();