From 2919393a35b996bcb88bed6d3f4768208bc43ecf Mon Sep 17 00:00:00 2001 From: Qasim Zaidi Date: Wed, 17 Dec 2014 17:20:30 +0530 Subject: [PATCH] remove multi , make it work with twemproxy --- lib/redis.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/redis.js b/lib/redis.js index 09ceb42..8525b08 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -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); + }); }); };