From 3c285e056977779f54569af93beb2f4e4501b813 Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Mon, 6 Jul 2015 13:43:26 +0300 Subject: [PATCH] adding redis support --- CONTRIBUTORS.txt | 1 + {{cookiecutter.repo_name}}/README.rst | 10 +++++----- .../config/settings/production.py | 20 ++++++++++--------- {{cookiecutter.repo_name}}/requirements.apt | 3 --- {{cookiecutter.repo_name}}/requirements.txt | 2 -- .../requirements/base.txt | 4 ++++ 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 89c8e3cc..09f9c779 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -45,6 +45,7 @@ Adam Dobrawy / @ad-m Daniele Tricoli / @eriol Harry Percival / @hjwp Cullen Rhodes / @c-rhodes +Burhan Khalid / @burhan Audrey Roy Greenfeld / @audreyr (and creator/maintainer of cookiecutter) * * Possesses commit rights diff --git a/{{cookiecutter.repo_name}}/README.rst b/{{cookiecutter.repo_name}}/README.rst index f746aa96..095c3ea5 100644 --- a/{{cookiecutter.repo_name}}/README.rst +++ b/{{cookiecutter.repo_name}}/README.rst @@ -19,7 +19,7 @@ Environment Variable Django Setting Development DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error -DJANGO_CACHES CACHES (default) locmem memcached +DJANGO_CACHES CACHES (default) locmem redis DJANGO_DATABASES DATABASES (default) See code See code DJANGO_DEBUG DEBUG True False DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error @@ -127,7 +127,7 @@ Run these commands to deploy the project to Heroku: heroku pg:promote DATABASE_URL heroku addons:create sendgrid:starter - heroku addons:create memcachier:dev + heroku addons:create heroku-redis:hobby-dev heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE heroku config:set DJANGO_SETTINGS_MODULE='config.settings.production' @@ -155,7 +155,7 @@ added just like in Heroku however you must ensure you have the relevant Dokku pl cd /var/lib/dokku/plugins git clone https://github.com/rlaneve/dokku-link.git link - git clone https://github.com/jezdez/dokku-memcached-plugin memcached + git clone https://github.com/luxifer/dokku-redis-plugin redis git clone https://github.com/jezdez/dokku-postgres-plugin postgres dokku plugins-install @@ -171,8 +171,8 @@ You can then deploy by running the following commands. git remote add dokku dokku@yourservername.com:{{cookiecutter.repo_name}} git push dokku master - ssh -t dokku@yourservername.com dokku memcached:create {{cookiecutter.repo_name}}-memcached - ssh -t dokku@yourservername.com dokku memcached:link {{cookiecutter.repo_name}}-memcached {{cookiecutter.repo_name}} + ssh -t dokku@yourservername.com dokku redis:create {{cookiecutter.repo_name}}-redis + ssh -t dokku@yourservername.com dokku redis:link {{cookiecutter.repo_name}}-redis {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE diff --git a/{{cookiecutter.repo_name}}/config/settings/production.py b/{{cookiecutter.repo_name}}/config/settings/production.py index d229cfb7..7fe260a1 100644 --- a/{{cookiecutter.repo_name}}/config/settings/production.py +++ b/{{cookiecutter.repo_name}}/config/settings/production.py @@ -127,15 +127,17 @@ DATABASES['default'] = env.db("DATABASE_URL") # CACHING # ------------------------------------------------------------------------------ -try: - # Only do this here because thanks to django-pylibmc-sasl and pylibmc - # memcacheify is painful to install on windows. - # See: https://github.com/rdegges/django-heroku-memcacheify - from memcacheify import memcacheify - CACHES = memcacheify() -except ImportError: - CACHES = { - 'default': env.cache_url("DJANGO_CACHE_URL", default="memcache://127.0.0.1:11211"), +# Heroku URL does not pass the DB number, so we parse it in +CACHES = { + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": "{0}/{1}".format(env.cache_url('REDIS_URL', default="redis://127.0.0.1:6379"), 0), + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + "IGNORE_EXCEPTIONS": True, # mimics memcache behavior. + # http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior + } } +} # Your production stuff: Below this line define 3rd party library settings diff --git a/{{cookiecutter.repo_name}}/requirements.apt b/{{cookiecutter.repo_name}}/requirements.apt index ae26b958..46cfaac2 100644 --- a/{{cookiecutter.repo_name}}/requirements.apt +++ b/{{cookiecutter.repo_name}}/requirements.apt @@ -19,9 +19,6 @@ libfreetype6-dev liblcms1-dev libwebp-dev -##pylibmc -libmemcached-dev -libssl-dev ##django-extensions graphviz-dev diff --git a/{{cookiecutter.repo_name}}/requirements.txt b/{{cookiecutter.repo_name}}/requirements.txt index 4311d9c2..d1197135 100644 --- a/{{cookiecutter.repo_name}}/requirements.txt +++ b/{{cookiecutter.repo_name}}/requirements.txt @@ -1,5 +1,3 @@ # This file is here because many Platforms as a Service look for # requirements.txt in the root directory of a project. -pylibmc==1.4.3 -django-heroku-memcacheify==0.8 -r requirements/production.txt diff --git a/{{cookiecutter.repo_name}}/requirements/base.txt b/{{cookiecutter.repo_name}}/requirements/base.txt index 3bf39542..ea8f09fa 100644 --- a/{{cookiecutter.repo_name}}/requirements/base.txt +++ b/{{cookiecutter.repo_name}}/requirements/base.txt @@ -34,4 +34,8 @@ django-autoslug==1.8.0 # Time zones support pytz==2015.4 +# Redis support +django-redis==4.2.0 +redis>=2.10.0 + # Your custom requirements go here