Skip to content
Open
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
35 changes: 18 additions & 17 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@ RedisRateHandler.prototype._increment_key = function (key, increment, rate_optio
rate = 1,
self = this;

this.client.multi()
.incrby(key, increment)
.ttl(key)
.exec(function (err, replies) {
this.client
.incrby(key, increment, function (err, replies) {

if (err) next(err);
if (err) next(err);

currentTime = (new Date()).getTime();
currentTime = (new Date()).getTime();

rate = replies[0];

// if the key was just created now, we need to set an expiraton
if(rate === increment) {
ttl = currentTime + (rate_options.interval * 1000);
self.client.expire(key, rate_options.interval);
} else {
ttl = currentTime + (replies[1] * 1000);
}

if (callback) callback(rate, ttl);
rate = replies;
self.client.ttl(key, function (err, rttl) {
if (err) next(err);

// if the key was just created now, we need to set an expiraton
if(rate === increment) {
ttl = currentTime + (rate_options.interval * 1000);
self.client.expire(key, rate_options.interval);
} else {
ttl = currentTime + (replies[1] * 1000);
}

if (callback) callback(rate, ttl);
});
});
};

Expand Down