Skip to content

Commit

Permalink
Merge pull request #17 from aexeagmbh/patch-redis
Browse files Browse the repository at this point in the history
Fix redis backend and add some doc
  • Loading branch information
andrewgodwin committed Sep 17, 2015
2 parents 454839d + 7cd5a02 commit d947d42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion channels/backends/redis_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def connection(self):
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(
Expand Down Expand Up @@ -59,7 +63,7 @@ def receive_many(self, channels):
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

Expand Down
14 changes: 14 additions & 0 deletions docs/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------

Expand Down
7 changes: 6 additions & 1 deletion docs/deploying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d947d42

Please sign in to comment.