You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Optimize statements and speed up the common case
This commit is contained in:
22
index.js
22
index.js
@@ -851,6 +851,14 @@ commands.forEach(function (fullCommand) {
|
||||
arg = [key].concat(arg);
|
||||
return this.send_command(command, arg, callback);
|
||||
}
|
||||
// Speed up the common case
|
||||
var len = arguments.length;
|
||||
if (len === 2) {
|
||||
return this.send_command(command, [key, arg]);
|
||||
}
|
||||
if (len === 3) {
|
||||
return this.send_command(command, [key, arg, callback]);
|
||||
}
|
||||
return this.send_command(command, utils.to_array(arguments));
|
||||
};
|
||||
RedisClient.prototype[command.toUpperCase()] = RedisClient.prototype[command];
|
||||
@@ -867,7 +875,15 @@ commands.forEach(function (fullCommand) {
|
||||
}
|
||||
this.queue.push([command, key].concat(arg));
|
||||
} else {
|
||||
this.queue.push([command].concat(utils.to_array(arguments)));
|
||||
// Speed up the common case
|
||||
var len = arguments.length;
|
||||
if (len === 2) {
|
||||
this.queue.push([command, key, arg]);
|
||||
} else if (len === 3) {
|
||||
this.queue.push([command, key, arg, callback]);
|
||||
} else {
|
||||
this.queue.push([command].concat(utils.to_array(arguments)));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
@@ -1102,9 +1118,7 @@ var createClient_tcp = function (port_arg, host_arg, options) {
|
||||
exports.createClient = function(port_arg, host_arg, options) {
|
||||
if (typeof port_arg === 'object' || port_arg === undefined) {
|
||||
options = port_arg || options || {};
|
||||
var host = options.host || default_host;
|
||||
var port = +options.port || default_port;
|
||||
return createClient_tcp(port, host, options);
|
||||
return createClient_tcp(+options.port, options.host, options);
|
||||
}
|
||||
if (typeof port_arg === 'number' || typeof port_arg === 'string' && /^\d+$/.test(port_arg)) {
|
||||
return createClient_tcp(port_arg, host_arg, options);
|
||||
|
Reference in New Issue
Block a user