Fix custom redislite to account for the none errors

This commit is contained in:
Jeremy Zhang 2017-04-22 01:39:06 -07:00
parent 2cbf3fec3a
commit 4b111c035f

View File

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