Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update redis commands to use array notation #9

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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