https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis
- add in requirements.txt
sudo pip install redis
- or from scritp.sh
echo "Installing Redis..."
if [ ! -x /usr/local/bin/redis-server ]; then
apt-get install -y build-essential tcl8.5
wget http://download.redis.io/releases/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make
make install
cd utils
./install_server.sh
fi
- channels
- pyhaikunator
- asgi_redis
INSTALLED_APPS = (
'....',
'channels',
'....',
)
# DJANGO CHANNELS CONFIGURATION
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://127.0.0.1:6379')],
},
"ROUTING": "miproject.miapp.routing.channel_routing",
},
}
# /asgi.py
import os
import channels.asgi
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "geventexample.settings")
channel_layer = channels.asgi.get_channel_layer()
# /wsgi.py
import os
from django.core.wsgi import get_wsgi_application
import channels.asgi # noqa
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tandlr.settings")
application = get_wsgi_application()
channel_layer = channels.asgi.get_channel_layer()
# -*- coding: utf-8 -*-
import logging
from channels import Group
from channels.sessions import channel_session
log = logging.getLogger(__name__)
@channel_session
def ws_connect(message):
Group('chat')
@channel_session
def ws_receive(message):
pass
@channel_session
def ws_disconnect(message):
pass
# -*- coding: utf-8 -*-
from channels.staticfiles import StaticFilesConsumer
from tandlr.notifications import consumers
channel_routing = {
'http.request': StaticFilesConsumer(),
# Wire up websocket channels to our consumers:
'websocket.connect': consumers.ws_connect,
'websocket.receive': consumers.ws_receive,
'websocket.disconnect': consumers.ws_disconnect,
}
@task
def runworker():
"""
Starts the development worker inside the Vagrant VM.
"""
with virtualenv():
run('python manage.py runworker')