Attempt to fix limiting

This commit is contained in:
Jeremy Zhang 2017-04-22 01:28:31 -07:00
parent 517e6f4ced
commit 3df40af71a
2 changed files with 12 additions and 5 deletions

View File

@ -114,7 +114,7 @@ def format_post_content(message):
message = "**<{}#{}>** {}".format(session['username'], session['discriminator'], message) # I would like to do a @ mention, but i am worried about notif spam
return message
@cache.cache(make_guildchannels_cache_key, expires=60)
@cache.cache(make_guildchannels_cache_key, expire=60)
def get_guild_channels(guild_id):
if user_unauthenticated():
member_roles = [guild_id] #equivilant to @everyone role

View File

@ -1,6 +1,7 @@
import urlparse
from limits.storage import Storage
from redislite import Redis
import time
class LimitsRedisLite(Storage): # For Python Limits
STORAGE_SCHEME = "redislite"
@ -14,12 +15,18 @@ class LimitsRedisLite(Storage): # For Python Limits
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:
if not self.redis_instance.exists(key):
self.redis_instance.set(key, 1)
self.redis_instance.expire(key, expiry)
self.redis_instance.expireat(key, int(time.time() + 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
def get(self, key):
print key + " " + str(int(self.redis_instance.get(key))) + " " + str(self.get_expiry(key))
return int(self.redis_instance.get(key))
def reset(self):
return self.redis_instance.flushdb()