For great justice.
parent
d017cb619b
commit
8b7cc5fad1
|
@ -3,5 +3,6 @@
|
|||
|
||||
from django.conf import settings
|
||||
|
||||
SAGE_REDIS = False
|
||||
REDIS_TTL = getattr(settings, "PAPIEZATOR_REDIS_TTL", 60*60*12)
|
||||
LOLGITHUB_URL = "I'm shy."
|
||||
|
|
|
@ -2,7 +2,7 @@ from papiezator.models import PopeImage, PerfectPope, DECIMAL_PLACES
|
|||
from PIL import Image
|
||||
from io import BytesIO
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from papiezator.papiezator_settings import REDIS_TTL
|
||||
from papiezator.papiezator_settings import REDIS_TTL, SAGE_REDIS
|
||||
try:
|
||||
from redis import Redis
|
||||
from redis.exceptions import ConnectionError as RedisConnectionError
|
||||
|
@ -72,14 +72,15 @@ def read_pope(width, height, pope_image):
|
|||
""" (int, int, Pope) -> bytes
|
||||
get pope and scale for display
|
||||
"""
|
||||
if redis:
|
||||
if redis and not SAGE_REDIS:
|
||||
try:
|
||||
|
||||
im = redis.get((width,height))
|
||||
key = (width,height, pope_image)
|
||||
im = redis.get(key)
|
||||
if not im:
|
||||
im = read_pope_from_fs(width, height, pope_image)
|
||||
redis.set((width,height), im)
|
||||
redis.expire((width,height), REDIS_TTL)
|
||||
redis.set(key, im)
|
||||
redis.expire(key, REDIS_TTL)
|
||||
|
||||
except RedisConnectionError:
|
||||
im = read_pope_from_fs(width, height, pope_image)
|
||||
|
|
Loading…
Reference in New Issue