From fa1082ff964d6c2ea4918233a960eb45888ac3f9 Mon Sep 17 00:00:00 2001 From: valentinogagliardi Date: Sun, 12 Jan 2020 13:13:41 +0100 Subject: [PATCH 1/3] ability to use a Redis connection URI - closes #402 --- django_q/brokers/redis_broker.py | 2 ++ docs/configure.rst | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/django_q/brokers/redis_broker.py b/django_q/brokers/redis_broker.py index 4f4f285..9750ffd 100644 --- a/django_q/brokers/redis_broker.py +++ b/django_q/brokers/redis_broker.py @@ -59,4 +59,6 @@ class Redis(Broker): def get_connection(list_key=Conf.PREFIX): if django_redis and Conf.DJANGO_REDIS: return django_redis.get_redis_connection(Conf.DJANGO_REDIS) + if isinstance(Conf.REDIS, str): + return redis.from_url(Conf.REDIS) return redis.StrictRedis(**Conf.REDIS) diff --git a/docs/configure.rst b/docs/configure.rst index 1507080..74bb8b0 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -180,6 +180,12 @@ Connection settings for Redis. Defaults:: } } +It's also possible to use a Redis connection URI: + + Q_CLUSTER = { + 'redis': 'redis://h:asdfqwer1234asdf@ec2-111-1-1-1.compute-1.amazonaws.com:111' + } + For more information on these settings please refer to the `Redis-py `__ documentation .. _django_redis: From 458697c09943b87ae818af7cb3d517577d87ba97 Mon Sep 17 00:00:00 2001 From: valentinogagliardi Date: Sun, 12 Jan 2020 19:23:19 +0100 Subject: [PATCH 2/3] add missing semicolon --- docs/configure.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configure.rst b/docs/configure.rst index 74bb8b0..e526763 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -180,7 +180,7 @@ Connection settings for Redis. Defaults:: } } -It's also possible to use a Redis connection URI: +It's also possible to use a Redis connection URI:: Q_CLUSTER = { 'redis': 'redis://h:asdfqwer1234asdf@ec2-111-1-1-1.compute-1.amazonaws.com:111' From c12e6184eb720a5230b0ad57acac4cda3746e5fe Mon Sep 17 00:00:00 2001 From: valentinogagliardi Date: Sun, 12 Jan 2020 20:10:06 +0100 Subject: [PATCH 3/3] add test for Redis URL --- django_q/tests/test_brokers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django_q/tests/test_brokers.py b/django_q/tests/test_brokers.py index 9d40b38..c6f7c1c 100644 --- a/django_q/tests/test_brokers.py +++ b/django_q/tests/test_brokers.py @@ -44,6 +44,10 @@ def test_redis(monkeypatch): broker = get_broker() with pytest.raises(Exception): broker.ping() + monkeypatch.setattr(Conf, 'REDIS', 'redis://127.0.0.1:7799') + broker = get_broker() + with pytest.raises(Exception): + broker.ping() def test_custom(monkeypatch):