Browse Source

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
greenkeeper-update-all
Ruben Bridgewater 9 years ago
parent
commit
4c6b84315e
  1. 15
      index.js
  2. 2
      test/commands/client.spec.js
  3. 2
      test/commands/dbsize.spec.js
  4. 2
      test/commands/del.spec.js
  5. 2
      test/commands/eval.spec.js
  6. 2
      test/commands/exits.spec.js
  7. 2
      test/commands/flushdb.spec.js
  8. 2
      test/commands/get.spec.js
  9. 2
      test/commands/getset.spec.js
  10. 2
      test/commands/hgetall.spec.js
  11. 2
      test/commands/hincrby.spec.js
  12. 2
      test/commands/hmget.spec.js
  13. 2
      test/commands/hmset.spec.js
  14. 2
      test/commands/hset.spec.js
  15. 2
      test/commands/incr.spec.js
  16. 2
      test/commands/keys.spec.js
  17. 2
      test/commands/mget.spec.js
  18. 2
      test/commands/msetnx.spec.js
  19. 2
      test/commands/multi.spec.js
  20. 2
      test/commands/rename.spec.js
  21. 2
      test/commands/renamenx.spec.js
  22. 2
      test/commands/script.spec.js
  23. 2
      test/commands/select.spec.js
  24. 2
      test/commands/set.spec.js
  25. 2
      test/commands/setex.spec.js
  26. 2
      test/commands/setnx.spec.js
  27. 2
      test/commands/sinter.spec.js
  28. 2
      test/commands/sismember.spec.js
  29. 2
      test/commands/slowlog.spec.js
  30. 2
      test/commands/smove.spec.js
  31. 2
      test/commands/sort.spec.js
  32. 2
      test/commands/srem.spec.js
  33. 2
      test/commands/type.spec.js
  34. 2
      test/commands/watch.spec.js

15
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);
}

2
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) {

2
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");

2
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));
});

2
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) {

2
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) {

2
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);
});

2
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);
});

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

2
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");

2
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) {

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

2
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');

2
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));
});

2
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);
});

2
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());

2
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());

2
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));
});

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

2
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));
});

2
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));
});

2
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();
});

2
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();

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

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

2
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));
});

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

2
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 () {

2
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"]);

2
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));
});

2
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);
});

2
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) {

2
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) {

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

Loading…
Cancel
Save