mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +01:00
Reimplement redislite to limiter, hopefully everything works this time
This commit is contained in:
parent
c497760f43
commit
4899c6d2d9
@ -15,7 +15,7 @@ app.config['SQLALCHEMY_DATABASE_URI'] = config['database-uri']
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Suppress the warning/no need this on for now.
|
||||
app.config['RATELIMIT_HEADERS_ENABLED'] = True
|
||||
app.config['SQLALCHEMY_POOL_RECYCLE'] = 250
|
||||
#app.config['RATELIMIT_STORAGE_URL'] = 'redislite://redislite.db'
|
||||
app.config['RATELIMIT_STORAGE_URL'] = 'redislite://redislite.db'
|
||||
app.secret_key = config['app-secret']
|
||||
|
||||
db.init_app(app)
|
||||
|
@ -16,13 +16,14 @@ class LimitsRedisLite(Storage): # For Python Limits
|
||||
|
||||
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))
|
||||
return
|
||||
oldexp = oldexp = self.get_expiry(key) - time.time()
|
||||
if oldexp <= 0:
|
||||
self.redis_instance.delete(key)
|
||||
return self.incr(key, expiry, elastic_expiry)
|
||||
self.redis_instance.set(key, int(self.redis_instance.get(key))+1, ex=int(round(oldexp)))
|
||||
return int(self.get(key))
|
||||
|
||||
def get(self, key):
|
||||
return int(self.redis_instance.get(key))
|
||||
|
Loading…
Reference in New Issue
Block a user