-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix regression, bring back socket support, fixes #950 #951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2f760c
fix(redis): bring back socket support
FGRibreau 7c90d8c
docs(README): specified that socket support does not mean reconnectio…
FGRibreau 9967f6d
fix(createClient): || should be && and support globalOptions === unde…
FGRibreau 1fde254
test(connection): added a test to ensure `socket` parameter is in opt…
FGRibreau 3d192cc
fix(index): clone() could not stringify a socket, because of a cyclin…
FGRibreau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,21 @@ function handle_detect_buffers_reply (reply, command, buffer_args) { | |
|
||
exports.debug_mode = /\bredis\b/i.test(process.env.NODE_DEBUG); | ||
|
||
function RedisClient (options) { | ||
function RedisClient (globalOptions) { | ||
globalOptions = globalOptions || {}; | ||
|
||
// extract socket if present | ||
var socket = globalOptions.socket; | ||
|
||
// ensure clone won't try to clone a socket | ||
globalOptions.socket = null; | ||
|
||
// Copy the options so they are not mutated | ||
options = clone(options); | ||
var options = clone(globalOptions); | ||
|
||
// add socket if present | ||
options.socket = socket; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if(stream){
this.stream = stream;
} |
||
|
||
events.EventEmitter.call(this); | ||
var cnx_options = {}; | ||
if (options.path) { | ||
|
@@ -109,8 +121,8 @@ function RedisClient (options) { | |
returnError: function (data) { | ||
self.return_error(data); | ||
}, | ||
returnBuffers: options.return_buffers || options.detect_buffers, | ||
name: options.parser | ||
returnBuffers: this.options.return_buffers || this.options.detect_buffers, | ||
name: this.options.parser | ||
}); | ||
this.create_stream(); | ||
} | ||
|
@@ -120,24 +132,29 @@ util.inherits(RedisClient, events.EventEmitter); | |
RedisClient.prototype.create_stream = function () { | ||
var self = this; | ||
|
||
// On a reconnect destroy the former stream and retry | ||
if (this.stream) { | ||
if(!this.options.socket){ | ||
// On a reconnect destroy the former stream and retry | ||
if (this.stream) { | ||
this.stream.removeAllListeners(); | ||
this.stream.destroy(); | ||
} | ||
} | ||
|
||
/* istanbul ignore if: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */ | ||
if (this.options.tls) { | ||
this.stream = tls.connect(this.connection_options); | ||
} else { | ||
this.stream = net.createConnection(this.connection_options); | ||
} | ||
|
||
/* istanbul ignore if: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */ | ||
if (this.options.tls) { | ||
this.stream = tls.connect(this.connection_options); | ||
} else { | ||
this.stream = net.createConnection(this.connection_options); | ||
} | ||
this.stream = this.options.socket; | ||
} | ||
|
||
if (this.options.connect_timeout) { | ||
this.stream.setTimeout(this.connect_timeout, function () { | ||
self.retry_totaltime = self.connect_timeout; | ||
self.connection_gone('timeout'); | ||
}); | ||
this.stream.setTimeout(this.connect_timeout, function () { | ||
self.retry_totaltime = self.connect_timeout; | ||
self.connection_gone('timeout'); | ||
}); | ||
} | ||
|
||
/* istanbul ignore next: travis does not work with stunnel atm. Therefor the tls tests are skipped on travis */ | ||
|
@@ -1281,6 +1298,9 @@ var createClient = function (port_arg, host_arg, options) { | |
} else { | ||
options.path = port_arg; | ||
} | ||
} else if (port_arg instanceof net.Socket && typeof host_arg === 'object') { | ||
options = clone(host_arg); | ||
options.socket = port_arg; | ||
} else if (typeof port_arg === 'object' || port_arg === undefined) { | ||
options = clone(port_arg || options); | ||
options.host = options.host || host_arg; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function RedisClient (options, socket) {