mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-26 06:57:04 +01:00
26 lines
763 B
Python
26 lines
763 B
Python
|
import urlparse
|
||
|
from limits.storage import Storage
|
||
|
from redislite import Redis
|
||
|
|
||
|
class LimitsRedisLite(Storage): # For Python Limits
|
||
|
STORAGE_SCHEME = "redislite"
|
||
|
def __init__(self, uri, **options):
|
||
|
self.redis_instance = Redis(urlparse.urlparse(uri).netloc)
|
||
|
|
||
|
def check(self):
|
||
|
return True
|
||
|
|
||
|
def get_expiry(self, key):
|
||
|
return self.redis_instance.ttl(key)
|
||
|
|
||
|
def incr(self, key, expiry, elastic_expiry=False):
|
||
|
if self.redis_instance.exists(key):
|
||
|
self.redis_instance.set(key, int(self.redis_instance.get(key))+1)
|
||
|
else:
|
||
|
self.redis_instance.set(key, 1)
|
||
|
self.redis_instance.expire(key, expiry)
|
||
|
return
|
||
|
|
||
|
def get(self, key):
|
||
|
return int(self.redis_instance.get(key))
|