fixes to redis again

This commit is contained in:
Jeremy Zhang 2017-04-22 01:46:35 -07:00
parent 4b111c035f
commit e4737444bd

View File

@ -12,14 +12,16 @@ class LimitsRedisLite(Storage): # For Python Limits
return True return True
def get_expiry(self, key): def get_expiry(self, key):
return self.redis_instance.ttl(key) or 0 return (self.redis_instance.ttl(key) or 0) + time.time()
def incr(self, key, expiry, elastic_expiry=False): def incr(self, key, expiry, elastic_expiry=False):
if not self.redis_instance.exists(key): if not self.redis_instance.exists(key):
self.redis_instance.set(key, 1, ex=expiry) self.redis_instance.set(key, 1)
self.redis_instance.expireat(key, int(time.time() + expiry))
else: else:
oldexp = self.get_expiry(key) oldexp = self.get_expiry(key)
self.redis_instance.set(key, int(self.redis_instance.get(key))+1, ex=oldexp) self.redis_instance.set(key, int(self.redis_instance.get(key))+1)
self.redis_instance.expireat(key, int(time.time() + oldexp))
return return
def get(self, key): def get(self, key):