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:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,5 +2,5 @@ node_modules
|
||||
.tern-port
|
||||
.nyc_output
|
||||
coverage
|
||||
npm-debug.log
|
||||
*.log
|
||||
*.rdb
|
||||
|
@@ -7,7 +7,7 @@ var redis = require("../index");
|
||||
var totalTime = 0;
|
||||
var metrics = require("metrics");
|
||||
var num_clients = parseInt(process.argv[2], 10) || 5;
|
||||
var num_requests = 20000;
|
||||
var num_requests = 50000;
|
||||
var tests = [];
|
||||
var versions_logged = false;
|
||||
var client_options = {
|
||||
|
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);
|
||||
|
@@ -11,7 +11,7 @@ function ReplyParser(return_buffers) {
|
||||
this.name = exports.name;
|
||||
this.return_buffers = return_buffers;
|
||||
|
||||
this._buffer = null;
|
||||
this._buffer = new Buffer(0);
|
||||
this._offset = 0;
|
||||
this._encoding = "utf-8";
|
||||
}
|
||||
@@ -171,18 +171,10 @@ ReplyParser.prototype.execute = function (buffer) {
|
||||
|
||||
ReplyParser.prototype.append = function (newBuffer) {
|
||||
|
||||
// first run
|
||||
if (this._buffer === null) {
|
||||
this._buffer = newBuffer;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// out of data
|
||||
if (this._offset >= this._buffer.length) {
|
||||
this._buffer = newBuffer;
|
||||
this._offset = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user