Skip to content

Commit fc6ea0e

Browse files
author
Rui Marinho
committed
Update watch and mget to use array arguments
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`.
1 parent 62794c3 commit fc6ea0e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ Limiter.prototype.get = function (fn) {
6969
var ex = (Date.now() + duration) / 1000 | 0;
7070

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

@@ -102,7 +102,7 @@ Limiter.prototype.get = function (fn) {
102102
}
103103

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

114114
function mget() {
115-
db.watch(count, function (err) {
115+
db.watch([count], function (err) {
116116
if (err) return fn(err);
117-
db.mget(count, limit, reset, function (err, res) {
117+
db.mget([count, limit, reset], function (err, res) {
118118
if (err) return fn(err);
119119
if (!res[0] && res[0] !== 0) return create();
120120

0 commit comments

Comments
 (0)