From 70bc429d0ba4461c6b50ee6b21f6214663b27f85 Mon Sep 17 00:00:00 2001 From: Bastian Hoyer Date: Wed, 16 Dec 2015 20:42:56 +0100 Subject: [PATCH] Fixed #39: Allow redis:// URL redis configuration --- channels/backends/redis_py.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/channels/backends/redis_py.py b/channels/backends/redis_py.py index 0cfbea9..3ef5c07 100644 --- a/channels/backends/redis_py.py +++ b/channels/backends/redis_py.py @@ -22,10 +22,12 @@ class RedisChannelBackend(BaseChannelBackend): # Make sure they provided some hosts, or provide a default if not hosts: hosts = [("localhost", 6379)] - for host, port in hosts: - assert isinstance(host, six.string_types) - assert int(port) - self.hosts = hosts + self.hosts = [] + for entry in hosts: + if isinstance(entry, six.string_types): + self.hosts.append(entry) + else: + self.hosts.append("redis://%s:%d/0" % (entry[0],entry[1])) self.prefix = prefix # Precalculate some values for ring selection self.ring_size = len(self.hosts) @@ -57,8 +59,7 @@ class RedisChannelBackend(BaseChannelBackend): # Catch bad indexes if not (0 <= index < self.ring_size): raise ValueError("There are only %s hosts - you asked for %s!" % (self.ring_size, index)) - host, port = self.hosts[index] - return redis.Redis(host=host, port=port) + return redis.Redis.from_url(self.hosts[index]) def send(self, channel, message): # if channel is no str (=> bytes) convert it