You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add optional callback option to duplicate function
This commit is contained in:
@@ -79,7 +79,11 @@ RedisClient.prototype.unref = function () {
|
||||
}
|
||||
};
|
||||
|
||||
RedisClient.prototype.duplicate = function (options) {
|
||||
RedisClient.prototype.duplicate = function (options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
var existing_options = utils.clone(this.options);
|
||||
options = utils.clone(options);
|
||||
for (var elem in options) { // jshint ignore: line
|
||||
@@ -87,5 +91,18 @@ RedisClient.prototype.duplicate = function (options) {
|
||||
}
|
||||
var client = new RedisClient(existing_options);
|
||||
client.selected_db = this.selected_db;
|
||||
if (typeof callback === 'function') {
|
||||
var ready_listener = function () {
|
||||
callback(null, client);
|
||||
client.removeAllListeners(error_listener);
|
||||
};
|
||||
var error_listener = function (err) {
|
||||
callback(err);
|
||||
client.end(true);
|
||||
};
|
||||
client.once('ready', ready_listener);
|
||||
client.once('error', error_listener);
|
||||
return;
|
||||
}
|
||||
return client;
|
||||
};
|
||||
|
Reference in New Issue
Block a user