diff --git a/channels/backends/redis_py.py b/channels/backends/redis_py.py index 6af662f..315c026 100644 --- a/channels/backends/redis_py.py +++ b/channels/backends/redis_py.py @@ -27,6 +27,10 @@ class RedisChannelBackend(BaseChannelBackend): return redis.Redis(host=self.host, port=self.port) def send(self, channel, message): + # if channel is no str (=> bytes) convert it + if not isinstance(channel, str): + channel = channel.decode('utf-8') + # Write out message into expiring key (avoids big items in list) key = self.prefix + uuid.uuid4().get_hex() self.connection.set( @@ -59,7 +63,7 @@ class RedisChannelBackend(BaseChannelBackend): content = self.connection.get(result[1]) if content is None: continue - return result[0][len(self.prefix):], json.loads(content) + return result[0][len(self.prefix):].decode("utf-8"), json.loads(content.decode("utf-8")) else: return None, None diff --git a/docs/backends.rst b/docs/backends.rst index e79dda9..b80911a 100644 --- a/docs/backends.rst +++ b/docs/backends.rst @@ -21,6 +21,20 @@ Database Redis ----- +To use the Redis backend you have to install the redis package:: + + pip install -U redis + +Also you need to set the following in the ``CHANNEL_BACKENDS`` setting:: + + CHANNEL_BACKENDS = { + "default": { + "BACKEND": "channels.backends.redis_py.RedisChannelBackend", + "HOST": "redis-hostname", + }, + } + + Writing Custom Backends ----------------------- diff --git a/docs/deploying.rst b/docs/deploying.rst index 5a47e36..49433b7 100644 --- a/docs/deploying.rst +++ b/docs/deploying.rst @@ -36,11 +36,16 @@ here's an example for a remote Redis server:: CHANNEL_BACKENDS = { "default": { - "BACKEND": "channels.backends.redis.RedisChannelBackend", + "BACKEND": "channels.backends.redis_py.RedisChannelBackend", "HOST": "redis-channel", }, } +To use the Redis backend you have to install the redis package:: + + pip install -U redis + + Make sure the same setting file is used across all your workers, interfaces and WSGI apps; without it, they won't be able to talk to each other and things will just fail to work.