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

remove multi , make it work with twemproxy #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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