Merge pull request #566 from liangliangyy/dev

增加redis缓存支持
sh_branch
且听风吟 4 years ago committed by GitHub
commit 2d5beb11f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -189,6 +189,14 @@ CACHES = {
'LOCATION': 'unique-snowflake',
}
}
# 使用redis作为缓存
if os.environ.get("DJANGO_REDIS_URL"):
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': f'redis://{os.environ.get("DJANGO_REDIS_URL")}',
}
}
SITE_ID = 1
BAIDU_NOTIFY_URL = os.environ.get('DJANGO_BAIDU_NOTIFY_URL') \

@ -9,6 +9,7 @@ import string
import uuid
from hashlib import sha256
import markdown
import requests
from django.contrib.sites.models import Site
from django.core.cache import cache
@ -33,7 +34,8 @@ def cache_decorator(expiration=3 * 60):
try:
view = args[0]
key = view.get_cache_key()
except BaseException:
except BaseException as e:
logger.warning(e)
key = None
if not key:
unique_str = repr((func, args, kwargs))
@ -97,7 +99,6 @@ def get_current_site():
class CommonMarkdown:
@staticmethod
def _convert_markdown(value):
import markdown
md = markdown.Markdown(
extensions=[
'extra',

@ -21,7 +21,7 @@ services:
volumes:
- ./bin/datas/mysql/:/var/lib/mysql
depends_on:
- memcached
- redis
container_name: db
djangoblog:
@ -38,10 +38,10 @@ services:
- DJANGO_MYSQL_PASSWORD=DjAnGoBlOg!2!Q@W#E
- DJANGO_MYSQL_HOST=db
- DJANGO_MYSQL_PORT=3306
- DJANGO_MEMCACHED_LOCATION=memcached:11211
- DJANGO_REDIS_URL=redis:6379
links:
- db
- memcached
- redis
depends_on:
- db
container_name: djangoblog
@ -58,9 +58,9 @@ services:
- djangoblog:djangoblog
container_name: nginx
memcached:
redis:
restart: always
image: memcached:latest
container_name: memcached
image: redis:latest
container_name: redis
ports:
- "11211:11211"
- "6379:6379"

Loading…
Cancel
Save