Skip to content

Commit

Permalink
Update redis commands to use array notation
Browse files Browse the repository at this point in the history
This is a small performance improvement since the `redis` module offers
a straight passthrough mode for command callbacks, since it does not
rely on parsing `arguments`.
  • Loading branch information
Rui Marinho committed Dec 31, 2014
1 parent 62794c3 commit 8e01ba9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ Limiter.prototype.get = function (fn) {
var ex = (Date.now() + duration) / 1000 | 0;

db.multi()
.set(count, max, 'PX', duration, 'NX')
.set(limit, max, 'PX', duration, 'NX')
.set(reset, ex, 'PX', duration, 'NX')
.set([count, max, 'PX', duration, 'NX'])
.set([limit, max, 'PX', duration, 'NX'])
.set([reset, ex, 'PX', duration, 'NX'])
.exec(function (err, res) {
if (err) return fn(err);
// If the request has failed, it means the values already
// If the request has failed, it means the values already
// exist in which case we need to get the latest values.
if (!res || !res[0]) return mget();

Expand Down Expand Up @@ -102,7 +102,7 @@ Limiter.prototype.get = function (fn) {
}

db.multi()
.set(count, n - 1, 'PX', ex * 1000 - Date.now(), 'XX')
.set([count, n - 1, 'PX', ex * 1000 - Date.now(), 'XX'])
.exec(function (err, res) {
if (err) return fn(err);
if (!res || !res[0]) return mget();
Expand All @@ -112,9 +112,9 @@ Limiter.prototype.get = function (fn) {
}

function mget() {
db.watch(count, function (err) {
db.watch([count], function (err) {
if (err) return fn(err);
db.mget(count, limit, reset, function (err, res) {
db.mget([count, limit, reset], function (err, res) {
if (err) return fn(err);
if (!res[0] && res[0] !== 0) return create();

Expand Down

0 comments on commit 8e01ba9

Please sign in to comment.