I'm currently trying to setup a Google app engine flex using a django framework with django-channels. for my current project i need a websocket, so i'm trying to reconstruct the tutorial offered on the website by Django-channels: https://channels.readthedocs.io/en/latest/tutorial/
Currently I'm stuck on adding redis to my google-app-flex instance. I followed the google documentation on setting up a redis connection - unfortunatly the example is in Flask: google doc I assume my error is trivial, and i just need to connect django CHANNEL_LAYERS to redis proporly.
executing sudo gcloud redis instances describe <redisname> --region=us-central1
gives me following responce:
executing sudo gcloud app describe
, this responce:
I configured my app.yaml
as follows:
# app.yaml
# [START runtime]
runtime: python
env: flex
entrypoint: daphne django_channels_heroku.asgi:application --port $PORT --bind 0.0.0.0
runtime_config:
python_version: 3
automatic_scaling:
min_num_instances: 1
max_num_instances: 7
# Update with Redis instance IP and port
env_variables:
REDISHOST: '<the ip in "host" from "Redis Describtion" image above>'
REDISPORT: '6379'
# Update with Redis instance network name
network:
name: default
# [END runtime]
..and in my settings.py i added this as the redis connection (which feels really wrong btw):
#settings.py
import redis
#settings.py stuff...
#connect to redis
redis_host = os.environ.get('REDISHOST', '127.0.0.1')
redis_port = int(os.environ.get('REDISPORT', 6379))
redis_client = redis.StrictRedis(host=redis_host, port=redis_port)
# Channels
ASGI_APPLICATION = "django_channels_heroku.routing.application"
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
what am i doing wrong. how do i connect to Redis using Django correctly?
here are some Links:
https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-flex
Django, Redis: Where to put connection-code
Deploying Django channels app on google flex engine
How to connect to Redis instance (memorystore) from Google's Standard App Engine (Python 3.7)
https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-flex
https://cloud.google.com/memorystore/docs/redis/quickstart-gcloud