From 4c6b84315eee277cf1bcbc704540ac9656ca0785 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 3 Sep 2015 23:42:00 +0200 Subject: [PATCH] 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 --- index.js | 15 +++++++-------- test/commands/client.spec.js | 2 +- test/commands/dbsize.spec.js | 2 +- test/commands/del.spec.js | 2 +- test/commands/eval.spec.js | 2 +- test/commands/exits.spec.js | 2 +- test/commands/flushdb.spec.js | 2 +- test/commands/get.spec.js | 2 +- test/commands/getset.spec.js | 2 +- test/commands/hgetall.spec.js | 2 +- test/commands/hincrby.spec.js | 2 +- test/commands/hmget.spec.js | 2 +- test/commands/hmset.spec.js | 2 +- test/commands/hset.spec.js | 2 +- test/commands/incr.spec.js | 2 +- test/commands/keys.spec.js | 2 +- test/commands/mget.spec.js | 2 +- test/commands/msetnx.spec.js | 2 +- test/commands/multi.spec.js | 2 +- test/commands/rename.spec.js | 2 +- test/commands/renamenx.spec.js | 2 +- test/commands/script.spec.js | 2 +- test/commands/select.spec.js | 2 +- test/commands/set.spec.js | 2 +- test/commands/setex.spec.js | 2 +- test/commands/setnx.spec.js | 2 +- test/commands/sinter.spec.js | 2 +- test/commands/sismember.spec.js | 2 +- test/commands/slowlog.spec.js | 2 +- test/commands/smove.spec.js | 2 +- test/commands/sort.spec.js | 2 +- test/commands/srem.spec.js | 2 +- test/commands/type.spec.js | 2 +- test/commands/watch.spec.js | 2 +- 34 files changed, 40 insertions(+), 41 deletions(-) diff --git a/index.js b/index.js index 5397e94e0d..a01073df98 100644 --- a/index.js +++ b/index.js @@ -624,14 +624,14 @@ RedisClient.prototype.return_reply = function (reply) { if (command_obj && !command_obj.sub_command) { if (typeof command_obj.callback === "function") { - if (this.options.detect_buffers && command_obj.buffer_args === false && 'exec' !== command_obj.command.toLowerCase()) { + if (this.options.detect_buffers && command_obj.buffer_args === false && 'exec' !== command_obj.command) { // If detect_buffers option was specified, then the reply from the parser will be Buffers. // If this command did not use Buffer arguments, then convert the reply to Strings here. reply = reply_to_strings(reply); } // TODO - confusing and error-prone that hgetall is special cased in two places - if (reply && 'hgetall' === command_obj.command.toLowerCase()) { + if (reply && 'hgetall' === command_obj.command) { reply = reply_to_object(reply); } @@ -730,8 +730,7 @@ RedisClient.prototype.send_command = function (command, args, callback) { // client.sadd(arg1, [arg2, arg3, arg4], cb); // converts to: // client.sadd(arg1, arg2, arg3, arg4, cb); - lcaseCommand = command.toLowerCase(); - if ((lcaseCommand === 'sadd' || lcaseCommand === 'srem') && args.length > 0 && Array.isArray(args[args.length - 1])) { + if ((command === 'sadd' || command === 'srem') && args.length > 0 && Array.isArray(args[args.length - 1])) { args = args.slice(0, -1).concat(args[args.length - 1]); } @@ -885,7 +884,7 @@ RedisClient.prototype.end = function () { function Multi(client, args) { this._client = client; - this.queue = [["MULTI"]]; + this.queue = [["multi"]]; if (Array.isArray(args)) { this.queue = this.queue.concat(args); } @@ -1061,7 +1060,7 @@ Multi.prototype.exec = function (callback) { if (args.length === 1 && Array.isArray(args[0])) { args = args[0]; } - if (command.toLowerCase() === 'hmset' && typeof args[1] === 'object') { + if (command === 'hmset' && typeof args[1] === 'object') { obj = args.pop(); Object.keys(obj).forEach(function (key) { args.push(key); @@ -1081,7 +1080,7 @@ Multi.prototype.exec = function (callback) { }, this); // TODO - make this callback part of Multi.prototype instead of creating it each time - return this._client.send_command("EXEC", [], function (err, replies) { + return this._client.send_command("exec", [], function (err, replies) { if (err) { if (callback) { errors.push(new Error(err)); @@ -1106,7 +1105,7 @@ Multi.prototype.exec = function (callback) { } // TODO - confusing and error-prone that hgetall is special cased in two places - if (reply && args[0].toLowerCase() === "hgetall") { + if (reply && args[0] === "hgetall") { replies[i - 1] = reply = reply_to_object(reply); } diff --git a/test/commands/client.spec.js b/test/commands/client.spec.js index 50d0f4899f..31bb5dc5e7 100644 --- a/test/commands/client.spec.js +++ b/test/commands/client.spec.js @@ -32,7 +32,7 @@ describe("The 'client' method", function () { describe('list', function () { it('lists connected clients', function (done) { - client.client("list", helper.match(pattern, done)); + client.client("LIST", helper.match(pattern, done)); }); it("lists connected clients when invoked with multi's chaining syntax", function (done) { diff --git a/test/commands/dbsize.spec.js b/test/commands/dbsize.spec.js index 5eb6958e9c..118ba0b15c 100644 --- a/test/commands/dbsize.spec.js +++ b/test/commands/dbsize.spec.js @@ -59,7 +59,7 @@ describe("The 'dbsize' method", function () { }); it("returns a zero db size", function (done) { - client.dbsize([], function (err, res) { + client.DBSIZE([], function (err, res) { helper.isNotError()(err, res); helper.isType.number()(err, res); assert.strictEqual(res, 0, "Initial db size should be 0"); diff --git a/test/commands/del.spec.js b/test/commands/del.spec.js index 8a110485c6..152e9c1e45 100644 --- a/test/commands/del.spec.js +++ b/test/commands/del.spec.js @@ -21,7 +21,7 @@ describe("The 'del' method", function () { it('allows a single key to be deleted', function (done) { client.set('foo', 'bar'); - client.del('foo', helper.isNumber(1)); + client.DEL('foo', helper.isNumber(1)); client.get('foo', helper.isNull(done)); }); diff --git a/test/commands/eval.spec.js b/test/commands/eval.spec.js index 0c3edb08fa..f5b46942a8 100644 --- a/test/commands/eval.spec.js +++ b/test/commands/eval.spec.js @@ -35,7 +35,7 @@ describe("The 'eval' method", function () { }); it('returns a string', function (done) { - client.eval("return 'hello world'", 0, helper.isString('hello world', done)); + client.EVAL("return 'hello world'", 0, helper.isString('hello world', done)); }); it('converts boolean true to integer 1', function (done) { diff --git a/test/commands/exits.spec.js b/test/commands/exits.spec.js index 2fd2ac5fce..3e7074268f 100644 --- a/test/commands/exits.spec.js +++ b/test/commands/exits.spec.js @@ -21,7 +21,7 @@ describe("The 'exits' method", function () { it('returns 1 if the key exists', function (done) { client.set('foo', 'bar'); - client.exists('foo', helper.isNumber(1, done)); + client.EXISTS('foo', helper.isNumber(1, done)); }); it('returns 0 if the key does not exist', function (done) { diff --git a/test/commands/flushdb.spec.js b/test/commands/flushdb.spec.js index c8e70bf58f..0bc2336a42 100644 --- a/test/commands/flushdb.spec.js +++ b/test/commands/flushdb.spec.js @@ -76,7 +76,7 @@ describe("The 'flushdb' method", function () { return done(err); } - client.flushdb(function (err, res) { + client.FLUSHDB(function (err, res) { helper.isString("OK")(err, res); done(err); }); diff --git a/test/commands/get.spec.js b/test/commands/get.spec.js index 3d3fd1e248..6defc2cf6f 100644 --- a/test/commands/get.spec.js +++ b/test/commands/get.spec.js @@ -64,7 +64,7 @@ describe("The 'get' method", function () { }); it("gets the value correctly", function (done) { - client.get(key, function (err, res) { + client.GET(key, function (err, res) { helper.isString(value)(err, res); done(err); }); diff --git a/test/commands/getset.spec.js b/test/commands/getset.spec.js index a47cd2d0b5..32b178beca 100644 --- a/test/commands/getset.spec.js +++ b/test/commands/getset.spec.js @@ -65,7 +65,7 @@ describe("The 'getset' method", function () { }); it("gets the value correctly", function (done) { - client.getset(key, value2, function (err, res) { + client.GETSET(key, value2, function (err, res) { helper.isString(value)(err, res); client.get(key, function (err, res) { helper.isString(value2)(err, res); diff --git a/test/commands/hgetall.spec.js b/test/commands/hgetall.spec.js index 0735bf31de..74b506e6f0 100644 --- a/test/commands/hgetall.spec.js +++ b/test/commands/hgetall.spec.js @@ -35,7 +35,7 @@ describe("The 'hgetall' method", function () { }); it('handles fetching keys set using an object', function (done) { - client.hmset("msg_test", {message: "hello"}, helper.isString("OK")); + client.HMSET("msg_test", {message: "hello"}, helper.isString("OK")); client.hgetall("msg_test", function (err, obj) { assert.strictEqual(1, Object.keys(obj).length); assert.strictEqual(obj.message, "hello"); diff --git a/test/commands/hincrby.spec.js b/test/commands/hincrby.spec.js index c8a7cfc93e..7d55f11c06 100644 --- a/test/commands/hincrby.spec.js +++ b/test/commands/hincrby.spec.js @@ -24,7 +24,7 @@ describe("The 'hincrby' method", function () { var field = "field 1"; client.HSET(hash, field, 33); - client.HINCRBY(hash, field, 10, helper.isNumber(43, done)); + client.hincrby(hash, field, 10, helper.isNumber(43, done)); }); it('increments a key that has not been set', function (done) { diff --git a/test/commands/hmget.spec.js b/test/commands/hmget.spec.js index af673bfac6..5f7bc325f2 100644 --- a/test/commands/hmget.spec.js +++ b/test/commands/hmget.spec.js @@ -23,7 +23,7 @@ describe("The 'hmget' method", function () { }); it('allows keys to be specified using multiple arguments', function (done) { - client.HMGET(hash, "0123456789", "some manner of key", function (err, reply) { + client.hmget(hash, "0123456789", "some manner of key", function (err, reply) { assert.strictEqual("abcdefghij", reply[0].toString()); assert.strictEqual("a type of value", reply[1].toString()); return done(err); diff --git a/test/commands/hmset.spec.js b/test/commands/hmset.spec.js index 859f0c26ab..d5cc11e3b8 100644 --- a/test/commands/hmset.spec.js +++ b/test/commands/hmset.spec.js @@ -31,7 +31,7 @@ describe("The 'hmset' method", function () { }); it('handles object-style syntax', function (done) { - client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}, helper.isString('OK')); + client.hmset(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}, helper.isString('OK')); client.HGETALL(hash, function (err, obj) { assert.equal(obj['0123456789'], 'abcdefghij'); assert.equal(obj['some manner of key'], 'a type of value'); diff --git a/test/commands/hset.spec.js b/test/commands/hset.spec.js index 7155e3297d..0424a97fd5 100644 --- a/test/commands/hset.spec.js +++ b/test/commands/hset.spec.js @@ -25,7 +25,7 @@ describe("The 'hset' method", function () { var field = new Buffer("0123456789"); var value = new Buffer("abcdefghij"); - client.HSET(hash, field, value, helper.isNumber(1)); + client.hset(hash, field, value, helper.isNumber(1)); client.HGET(hash, field, helper.isString(value.toString(), done)); }); diff --git a/test/commands/incr.spec.js b/test/commands/incr.spec.js index bc303da651..f4d6b8ea47 100644 --- a/test/commands/incr.spec.js +++ b/test/commands/incr.spec.js @@ -69,7 +69,7 @@ describe("The 'incr' method", function () { }); it("changes the last digit from 2 to 3", function (done) { - client.incr(key, function (err, res) { + client.INCR(key, function (err, res) { helper.isString("9007199254740993")(err, res); done(err); }); diff --git a/test/commands/keys.spec.js b/test/commands/keys.spec.js index aaf6ddadf4..664ec4e4f3 100644 --- a/test/commands/keys.spec.js +++ b/test/commands/keys.spec.js @@ -46,7 +46,7 @@ describe("The 'keys' method", function () { return a.concat(b); }), helper.isString("OK")); - client.KEYS("multibulk:*", function(err, results) { + client.keys("multibulk:*", function(err, results) { assert.deepEqual(keys_values.map(function(val) { return val[0]; }).sort(), results.sort()); diff --git a/test/commands/mget.spec.js b/test/commands/mget.spec.js index 270ff37854..3d506c6d10 100644 --- a/test/commands/mget.spec.js +++ b/test/commands/mget.spec.js @@ -33,7 +33,7 @@ describe("The 'mget' method", function () { }); it('handles fetching multiple keys via an array', function (done) { - client.MGET(["mget keys 1", "mget keys 2", "mget keys 3"], function (err, results) { + client.mget(["mget keys 1", "mget keys 2", "mget keys 3"], function (err, results) { assert.strictEqual("mget val 1", results[0].toString()); assert.strictEqual("mget val 2", results[1].toString()); assert.strictEqual("mget val 3", results[2].toString()); diff --git a/test/commands/msetnx.spec.js b/test/commands/msetnx.spec.js index 8084677839..1ac77e1894 100644 --- a/test/commands/msetnx.spec.js +++ b/test/commands/msetnx.spec.js @@ -26,7 +26,7 @@ describe("The 'msetnx' method", function () { }); it('sets multiple keys if all keys are not set', function (done) { - client.MSETNX(["mset3", "val3", "mset4", "val4"], helper.isNumber(1)); + client.msetnx(["mset3", "val3", "mset4", "val4"], helper.isNumber(1)); client.exists(["mset3"], helper.isNumber(1)); client.exists(["mset3"], helper.isNumber(1, done)); }); diff --git a/test/commands/multi.spec.js b/test/commands/multi.spec.js index 41ae51f075..11aae4f8b0 100644 --- a/test/commands/multi.spec.js +++ b/test/commands/multi.spec.js @@ -62,7 +62,7 @@ describe("The 'multi' method", function () { var multi1, multi2; // Provoke an error at queue time - multi1 = client.multi(); + multi1 = client.MULTI(); multi1.mset("multifoo", "10", "multibar", "20", helper.isString("OK")); multi1.set("foo2", helper.isError()); multi1.incr("multifoo", helper.isNumber(11)); diff --git a/test/commands/rename.spec.js b/test/commands/rename.spec.js index 6196994c58..d506bec46c 100644 --- a/test/commands/rename.spec.js +++ b/test/commands/rename.spec.js @@ -21,7 +21,7 @@ describe("The 'rename' method", function () { it('populates the new key', function (done) { client.set(['foo', 'bar'], helper.isString("OK")); - client.RENAME(["foo", "new foo"], helper.isString("OK")); + client.rename(["foo", "new foo"], helper.isString("OK")); client.exists(["new foo"], helper.isNumber(1, done)); }); diff --git a/test/commands/renamenx.spec.js b/test/commands/renamenx.spec.js index 454d046727..dc2224ee58 100644 --- a/test/commands/renamenx.spec.js +++ b/test/commands/renamenx.spec.js @@ -21,7 +21,7 @@ describe("The 'renamenx' method", function () { it('renames the key if target does not yet exist', function (done) { client.set('foo', 'bar', helper.isString('OK')); - client.renamenx('foo', 'foo2', helper.isNumber(1)); + client.RENAMENX('foo', 'foo2', helper.isNumber(1)); client.exists('foo', helper.isNumber(0)); client.exists(['foo2'], helper.isNumber(1, done)); }); diff --git a/test/commands/script.spec.js b/test/commands/script.spec.js index 254ab6045f..663bbc5d9d 100644 --- a/test/commands/script.spec.js +++ b/test/commands/script.spec.js @@ -33,7 +33,7 @@ describe("The 'script' method", function () { }); it("loads script with client.script('load')", function (done) { - client.script("load", command, function(err, result) { + client.SCRIPT("load", command, function(err, result) { assert.strictEqual(result, commandSha); return done(); }); diff --git a/test/commands/select.spec.js b/test/commands/select.spec.js index bdc87668d1..1f0c38581f 100644 --- a/test/commands/select.spec.js +++ b/test/commands/select.spec.js @@ -48,7 +48,7 @@ describe("The 'select' method", function () { it("changes the database and calls the callback", function (done) { // default value of null means database 0 will be used. assert.strictEqual(client.selected_db, null, "default db should be null"); - client.select(1, function (err, res) { + client.SELECT(1, function (err, res) { helper.isNotError()(err, res); assert.strictEqual(client.selected_db, 1, "db should be 1 after select"); done(); diff --git a/test/commands/set.spec.js b/test/commands/set.spec.js index 1674051c8f..1ef70fc7db 100644 --- a/test/commands/set.spec.js +++ b/test/commands/set.spec.js @@ -58,7 +58,7 @@ describe("The 'set' method", function () { describe("and a callback is specified", function () { describe("with valid parameters", function () { it("sets the value correctly", function (done) { - client.set(key, value, function (err, res) { + client.SET(key, value, function (err, res) { helper.isNotError()(err, res); client.get(key, function (err, res) { helper.isString(value)(err, res); diff --git a/test/commands/setex.spec.js b/test/commands/setex.spec.js index 71e55b20e7..334f92cdbf 100644 --- a/test/commands/setex.spec.js +++ b/test/commands/setex.spec.js @@ -21,7 +21,7 @@ describe("The 'setex' method", function () { }); it('sets a key with an expiry', function (done) { - client.SETEX(["setex key", "100", "setex val"], helper.isString("OK")); + client.setex(["setex key", "100", "setex val"], helper.isString("OK")); client.exists(["setex key"], helper.isNumber(1)); client.ttl(['setex key'], function (err, ttl) { assert.ok(ttl > 0); diff --git a/test/commands/setnx.spec.js b/test/commands/setnx.spec.js index 8e426d6c01..0092a33fac 100644 --- a/test/commands/setnx.spec.js +++ b/test/commands/setnx.spec.js @@ -20,7 +20,7 @@ describe("The 'setnx' method", function () { }); it('sets key if it does not have a value', function (done) { - client.setnx('foo', 'banana', helper.isNumber(1)); + client.SETNX('foo', 'banana', helper.isNumber(1)); client.get('foo', helper.isString('banana', done)); }); diff --git a/test/commands/sinter.spec.js b/test/commands/sinter.spec.js index 59b751fb5f..e03973755c 100644 --- a/test/commands/sinter.spec.js +++ b/test/commands/sinter.spec.js @@ -29,7 +29,7 @@ describe("The 'sinter' method", function () { client.sadd('sb', 'c', helper.isNumber(1)); client.sadd('sb', 'd', helper.isNumber(1)); - client.sinter('sa', 'sb', function (err, intersection) { + client.SINTER('sa', 'sb', function (err, intersection) { assert.equal(intersection.length, 2); assert.deepEqual(intersection.sort(), [ 'b', 'c' ]); return done(err); diff --git a/test/commands/sismember.spec.js b/test/commands/sismember.spec.js index 1e1d29e5af..d5e4a554f8 100644 --- a/test/commands/sismember.spec.js +++ b/test/commands/sismember.spec.js @@ -25,7 +25,7 @@ describe("The 'sismember' method", function () { it('returns 1 if the value is in the set', function (done) { client.sadd('foo', 'banana', helper.isNumber(1)); - client.sismember('foo', 'banana', helper.isNumber(1, done)); + client.SISMEMBER('foo', 'banana', helper.isNumber(1, done)); }); afterEach(function () { diff --git a/test/commands/slowlog.spec.js b/test/commands/slowlog.spec.js index c64b0ebf58..846694d54d 100644 --- a/test/commands/slowlog.spec.js +++ b/test/commands/slowlog.spec.js @@ -25,7 +25,7 @@ describe("The 'slowlog' method", function () { client.slowlog("reset", helper.isString("OK")); client.set("foo", "bar", helper.isString("OK")); client.get("foo", helper.isString("bar")); - client.slowlog("get", function (err, res) { + client.SLOWLOG("get", function (err, res) { assert.equal(res.length, 3); assert.equal(res[0][3].length, 2); assert.deepEqual(res[1][3], ["set", "foo", "bar"]); diff --git a/test/commands/smove.spec.js b/test/commands/smove.spec.js index abdc2e476a..4b65b150cd 100644 --- a/test/commands/smove.spec.js +++ b/test/commands/smove.spec.js @@ -28,7 +28,7 @@ describe("The 'smove' method", function () { it("does not move a value if it does not exist in the first set", function (done) { client.sadd('foo', 'x', helper.isNumber(1)); - client.smove('foo', 'bar', 'y', helper.isNumber(0)); + client.SMOVE('foo', 'bar', 'y', helper.isNumber(0)); client.sismember('foo', 'y', helper.isNumber(0)); client.sismember('bar', 'y', helper.isNumber(0, done)); }); diff --git a/test/commands/sort.spec.js b/test/commands/sort.spec.js index d50f176b64..e5985137de 100644 --- a/test/commands/sort.spec.js +++ b/test/commands/sort.spec.js @@ -30,7 +30,7 @@ describe("The 'sort' method", function () { }); it('sorts in descending alphabetical order', function (done) { - client.sort('y', 'desc', 'alpha', function (err, sorted) { + client.SORT('y', 'desc', 'alpha', function (err, sorted) { assert.deepEqual(sorted, ['d', 'c', 'b', 'a']); return done(err); }); diff --git a/test/commands/srem.spec.js b/test/commands/srem.spec.js index a62dd6bc83..8afd79afed 100644 --- a/test/commands/srem.spec.js +++ b/test/commands/srem.spec.js @@ -27,7 +27,7 @@ describe("The 'srem' method", function () { }); it('handles attempting to remove a missing value', function (done) { - client.srem('set0', 'member0', helper.isNumber(0, done)); + client.SREM('set0', 'member0', helper.isNumber(0, done)); }); it('allows multiple values to be removed', function (done) { diff --git a/test/commands/type.spec.js b/test/commands/type.spec.js index 1410b325de..e4ad527d91 100644 --- a/test/commands/type.spec.js +++ b/test/commands/type.spec.js @@ -26,7 +26,7 @@ describe("The 'type' method", function () { it('reports list type', function (done) { client.rpush(["list key", "should be a list"], helper.isNumber(1)); - client.TYPE(["list key"], helper.isString("list", done)); + client.type(["list key"], helper.isString("list", done)); }); it('reports set type', function (done) { diff --git a/test/commands/watch.spec.js b/test/commands/watch.spec.js index 6cbc63e2f4..11cd4470f0 100644 --- a/test/commands/watch.spec.js +++ b/test/commands/watch.spec.js @@ -32,7 +32,7 @@ describe("The 'watch' method", function () { }); it('does not execute transaction if watched key was modified prior to execution', function (done) { - client.watch(watched); + client.WATCH(watched); client.incr(watched); var multi = client.multi(); multi.incr(watched);