Skip to content

Commit c947e8f

Browse files
committed
Merge pull request #817 from fintura/speedup
Tiny speedup by removing command.toLowerCase(). Fixes #605
2 parents b63e980 + 1c1c4ea commit c947e8f

35 files changed

+44
-45
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ the second word as first parameter:
551551

552552
## client.send_command(command_name, args, callback)
553553

554-
Used internally to send commands to Redis. For convenience, nearly all commands that are published on the Redis
555-
Wiki have been added to the `client` object. However, if I missed any, or if new commands are introduced before
556-
this library is updated, you can use `send_command()` to send arbitrary commands to Redis.
554+
Used internally to send commands to Redis. Nearly all Redis commands have been added to the `client` object.
555+
However, if new commands are introduced before this library is updated, you can use `send_command()` to send arbitrary commands to Redis.
556+
The command has to be lower case.
557557

558558
All commands are sent as multi-bulk commands. `args` can either be an Array of arguments, or omitted.
559559

index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,14 @@ RedisClient.prototype.return_reply = function (reply) {
624624

625625
if (command_obj && !command_obj.sub_command) {
626626
if (typeof command_obj.callback === "function") {
627-
if (this.options.detect_buffers && command_obj.buffer_args === false && 'exec' !== command_obj.command.toLowerCase()) {
627+
if (this.options.detect_buffers && command_obj.buffer_args === false && 'exec' !== command_obj.command) {
628628
// If detect_buffers option was specified, then the reply from the parser will be Buffers.
629629
// If this command did not use Buffer arguments, then convert the reply to Strings here.
630630
reply = reply_to_strings(reply);
631631
}
632632

633633
// TODO - confusing and error-prone that hgetall is special cased in two places
634-
if (reply && 'hgetall' === command_obj.command.toLowerCase()) {
634+
if (reply && 'hgetall' === command_obj.command) {
635635
reply = reply_to_object(reply);
636636
}
637637

@@ -692,7 +692,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
692692
}
693693

694694
RedisClient.prototype.send_command = function (command, args, callback) {
695-
var arg, command_obj, i, il, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type, lcaseCommand;
695+
var arg, command_obj, i, il, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type;
696696

697697
if (typeof command !== "string") {
698698
throw new Error("First argument to send_command must be the command name string, not " + typeof command);
@@ -730,8 +730,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
730730
// client.sadd(arg1, [arg2, arg3, arg4], cb);
731731
// converts to:
732732
// client.sadd(arg1, arg2, arg3, arg4, cb);
733-
lcaseCommand = command.toLowerCase();
734-
if ((lcaseCommand === 'sadd' || lcaseCommand === 'srem') && args.length > 0 && Array.isArray(args[args.length - 1])) {
733+
if ((command === 'sadd' || command === 'srem') && args.length > 0 && Array.isArray(args[args.length - 1])) {
735734
args = args.slice(0, -1).concat(args[args.length - 1]);
736735
}
737736

@@ -885,7 +884,7 @@ RedisClient.prototype.end = function () {
885884

886885
function Multi(client, args) {
887886
this._client = client;
888-
this.queue = [["MULTI"]];
887+
this.queue = [["multi"]];
889888
if (Array.isArray(args)) {
890889
this.queue = this.queue.concat(args);
891890
}
@@ -1061,7 +1060,7 @@ Multi.prototype.exec = function (callback) {
10611060
if (args.length === 1 && Array.isArray(args[0])) {
10621061
args = args[0];
10631062
}
1064-
if (command.toLowerCase() === 'hmset' && typeof args[1] === 'object') {
1063+
if (command === 'hmset' && typeof args[1] === 'object') {
10651064
obj = args.pop();
10661065
Object.keys(obj).forEach(function (key) {
10671066
args.push(key);
@@ -1081,7 +1080,7 @@ Multi.prototype.exec = function (callback) {
10811080
}, this);
10821081

10831082
// TODO - make this callback part of Multi.prototype instead of creating it each time
1084-
return this._client.send_command("EXEC", [], function (err, replies) {
1083+
return this._client.send_command("exec", [], function (err, replies) {
10851084
if (err) {
10861085
if (callback) {
10871086
errors.push(new Error(err));
@@ -1106,7 +1105,7 @@ Multi.prototype.exec = function (callback) {
11061105
}
11071106

11081107
// TODO - confusing and error-prone that hgetall is special cased in two places
1109-
if (reply && args[0].toLowerCase() === "hgetall") {
1108+
if (reply && args[0] === "hgetall") {
11101109
replies[i - 1] = reply = reply_to_object(reply);
11111110
}
11121111

test/commands/client.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("The 'client' method", function () {
3232

3333
describe('list', function () {
3434
it('lists connected clients', function (done) {
35-
client.client("list", helper.match(pattern, done));
35+
client.client("LIST", helper.match(pattern, done));
3636
});
3737

3838
it("lists connected clients when invoked with multi's chaining syntax", function (done) {

test/commands/dbsize.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe("The 'dbsize' method", function () {
5959
});
6060

6161
it("returns a zero db size", function (done) {
62-
client.dbsize([], function (err, res) {
62+
client.DBSIZE([], function (err, res) {
6363
helper.isNotError()(err, res);
6464
helper.isType.number()(err, res);
6565
assert.strictEqual(res, 0, "Initial db size should be 0");

test/commands/del.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("The 'del' method", function () {
2121

2222
it('allows a single key to be deleted', function (done) {
2323
client.set('foo', 'bar');
24-
client.del('foo', helper.isNumber(1));
24+
client.DEL('foo', helper.isNumber(1));
2525
client.get('foo', helper.isNull(done));
2626
});
2727

test/commands/eval.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("The 'eval' method", function () {
3535
});
3636

3737
it('returns a string', function (done) {
38-
client.eval("return 'hello world'", 0, helper.isString('hello world', done));
38+
client.EVAL("return 'hello world'", 0, helper.isString('hello world', done));
3939
});
4040

4141
it('converts boolean true to integer 1', function (done) {

test/commands/exits.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("The 'exits' method", function () {
2121

2222
it('returns 1 if the key exists', function (done) {
2323
client.set('foo', 'bar');
24-
client.exists('foo', helper.isNumber(1, done));
24+
client.EXISTS('foo', helper.isNumber(1, done));
2525
});
2626

2727
it('returns 0 if the key does not exist', function (done) {

test/commands/flushdb.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe("The 'flushdb' method", function () {
7676
return done(err);
7777
}
7878

79-
client.flushdb(function (err, res) {
79+
client.FLUSHDB(function (err, res) {
8080
helper.isString("OK")(err, res);
8181
done(err);
8282
});

test/commands/get.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("The 'get' method", function () {
6464
});
6565

6666
it("gets the value correctly", function (done) {
67-
client.get(key, function (err, res) {
67+
client.GET(key, function (err, res) {
6868
helper.isString(value)(err, res);
6969
done(err);
7070
});

test/commands/getset.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe("The 'getset' method", function () {
6565
});
6666

6767
it("gets the value correctly", function (done) {
68-
client.getset(key, value2, function (err, res) {
68+
client.GETSET(key, value2, function (err, res) {
6969
helper.isString(value)(err, res);
7070
client.get(key, function (err, res) {
7171
helper.isString(value2)(err, res);

0 commit comments

Comments
 (0)