Skip to content

Commit 4c6b843

Browse files
author
Ruben Bridgewater
committed
Tiny speedup by removing command.toLowerCase()
This is not necessary as the command itself is only used from inside the code and as they are (now) all lower case it is safe to remove the toLowerCase
1 parent b63e980 commit 4c6b843

34 files changed

+40
-41
lines changed

index.js

Lines changed: 7 additions & 8 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

@@ -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);

test/commands/hgetall.spec.js

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

3737
it('handles fetching keys set using an object', function (done) {
38-
client.hmset("msg_test", {message: "hello"}, helper.isString("OK"));
38+
client.HMSET("msg_test", {message: "hello"}, helper.isString("OK"));
3939
client.hgetall("msg_test", function (err, obj) {
4040
assert.strictEqual(1, Object.keys(obj).length);
4141
assert.strictEqual(obj.message, "hello");

0 commit comments

Comments
 (0)