mirror of
https://github.com/django/daphne.git
synced 2025-07-11 00:12:18 +03:00
Fixed #39: Allow redis:// URL redis configuration
This commit is contained in:
parent
a6073157f4
commit
70bc429d0b
|
@ -22,10 +22,12 @@ class RedisChannelBackend(BaseChannelBackend):
|
||||||
# Make sure they provided some hosts, or provide a default
|
# Make sure they provided some hosts, or provide a default
|
||||||
if not hosts:
|
if not hosts:
|
||||||
hosts = [("localhost", 6379)]
|
hosts = [("localhost", 6379)]
|
||||||
for host, port in hosts:
|
self.hosts = []
|
||||||
assert isinstance(host, six.string_types)
|
for entry in hosts:
|
||||||
assert int(port)
|
if isinstance(entry, six.string_types):
|
||||||
self.hosts = hosts
|
self.hosts.append(entry)
|
||||||
|
else:
|
||||||
|
self.hosts.append("redis://%s:%d/0" % (entry[0],entry[1]))
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
# Precalculate some values for ring selection
|
# Precalculate some values for ring selection
|
||||||
self.ring_size = len(self.hosts)
|
self.ring_size = len(self.hosts)
|
||||||
|
@ -57,8 +59,7 @@ class RedisChannelBackend(BaseChannelBackend):
|
||||||
# Catch bad indexes
|
# Catch bad indexes
|
||||||
if not (0 <= index < self.ring_size):
|
if not (0 <= index < self.ring_size):
|
||||||
raise ValueError("There are only %s hosts - you asked for %s!" % (self.ring_size, index))
|
raise ValueError("There are only %s hosts - you asked for %s!" % (self.ring_size, index))
|
||||||
host, port = self.hosts[index]
|
return redis.Redis.from_url(self.hosts[index])
|
||||||
return redis.Redis(host=host, port=port)
|
|
||||||
|
|
||||||
def send(self, channel, message):
|
def send(self, channel, message):
|
||||||
# if channel is no str (=> bytes) convert it
|
# if channel is no str (=> bytes) convert it
|
||||||
|
|
Loading…
Reference in New Issue
Block a user