Remove keyvalue properties in favor of redis

This commit is contained in:
Jeremy Zhang
2017-12-29 17:40:32 +00:00
parent 7d2fd9056d
commit 348580dcbb
11 changed files with 53 additions and 170 deletions

View File

@ -2,8 +2,7 @@ from config import config
import json
from requests_oauthlib import OAuth2Session
from flask import session, abort, url_for
from titanembeds.database import get_keyvalproperty, set_keyvalproperty
from titanembeds.utils import make_user_cache_key
from titanembeds.utils import redis_store, make_user_cache_key
authorize_url = "https://discordapp.com/api/oauth2/authorize"
token_url = "https://discordapp.com/api/oauth2/token"
@ -45,14 +44,14 @@ def user_has_permission(permission, index):
return bool((int(permission) >> index) & 1)
def get_user_guilds():
cache = get_keyvalproperty("OAUTH/USERGUILDS/"+str(make_user_cache_key()))
cache = redis_store.get("OAUTH/USERGUILDS/"+str(make_user_cache_key()))
if cache:
return cache
return cache.decode("utf-8")
req = discordrest_from_user("/users/@me/guilds")
if req.status_code != 200:
abort(req.status_code)
req = json.dumps(req.json())
set_keyvalproperty("OAUTH/USERGUILDS/"+str(make_user_cache_key()), req, 250)
redis_store.set("OAUTH/USERGUILDS/"+str(make_user_cache_key()), req, 250)
return req
def get_user_managed_servers():