From c62c79e83377a1e443b1a5c1f53a94de396560c8 Mon Sep 17 00:00:00 2001 From: dmarkey Date: Wed, 26 Aug 2020 15:35:52 +0100 Subject: [PATCH 1/7] Add redis SSL support --- mrq/context.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mrq/context.py b/mrq/context.py index ec3368aa..13b7bddb 100644 --- a/mrq/context.py +++ b/mrq/context.py @@ -140,6 +140,10 @@ def versiontuple(v): import redis as pyredis + ssl = False + if attr.startswith("rediss"): + ssl = True + urllib.parse.uses_netloc.append('redis') redis_url = urllib.parse.urlparse(config_obj) @@ -153,7 +157,8 @@ def versiontuple(v): password=redis_url.password if redis_url.password is not None else redis_url.username, max_connections=int(config.get("redis_max_connections")), timeout=int(config.get("redis_timeout")), - decode_responses=False + decode_responses=False, + ssl=ssl ) return pyredis.StrictRedis(connection_pool=redis_pool) From ae59a2dc89ff4d6795971e0378c72aa6359a7854 Mon Sep 17 00:00:00 2001 From: David Markey Date: Wed, 26 Aug 2020 15:52:23 +0100 Subject: [PATCH 2/7] Update requirements-base.txt --- requirements-base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-base.txt b/requirements-base.txt index 02b914b5..3368e735 100644 --- a/requirements-base.txt +++ b/requirements-base.txt @@ -1,5 +1,5 @@ argparse>=1.1 -redis==2.10.6 +redis==3.5.3 pymongo==3.7.2 gevent>=1.2.2 ujson>=1.33 From 0108b23e6c6777e6a0815f1dc557b2fb8c71ccc7 Mon Sep 17 00:00:00 2001 From: David Markey Date: Wed, 26 Aug 2020 15:58:48 +0100 Subject: [PATCH 3/7] Update requirements-base.txt --- requirements-base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-base.txt b/requirements-base.txt index 3368e735..02b914b5 100644 --- a/requirements-base.txt +++ b/requirements-base.txt @@ -1,5 +1,5 @@ argparse>=1.1 -redis==3.5.3 +redis==2.10.6 pymongo==3.7.2 gevent>=1.2.2 ujson>=1.33 From 41b74bfb3a4bd149bda9308b4b6551d84cc08fa8 Mon Sep 17 00:00:00 2001 From: dmarkey Date: Wed, 26 Aug 2020 15:59:03 +0100 Subject: [PATCH 4/7] Add SSL connectionclass --- mrq/context.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mrq/context.py b/mrq/context.py index 13b7bddb..74327534 100644 --- a/mrq/context.py +++ b/mrq/context.py @@ -139,10 +139,11 @@ def versiontuple(v): if isinstance(config_obj, basestring): import redis as pyredis + import redis.connection as pyredisconnection - ssl = False + connection_class = pyredisconnection.Connection if attr.startswith("rediss"): - ssl = True + connection_class = pyredisconnection.SSLConnection urllib.parse.uses_netloc.append('redis') redis_url = urllib.parse.urlparse(config_obj) @@ -158,7 +159,7 @@ def versiontuple(v): max_connections=int(config.get("redis_max_connections")), timeout=int(config.get("redis_timeout")), decode_responses=False, - ssl=ssl + connection_class=connection_class ) return pyredis.StrictRedis(connection_pool=redis_pool) From 0aabe06cd9144b0af24b16b9d6e0c2d67c90befe Mon Sep 17 00:00:00 2001 From: dmarkey Date: Wed, 26 Aug 2020 16:08:06 +0100 Subject: [PATCH 5/7] Some debugging --- mrq/context.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mrq/context.py b/mrq/context.py index 74327534..e01756d3 100644 --- a/mrq/context.py +++ b/mrq/context.py @@ -144,6 +144,8 @@ def versiontuple(v): connection_class = pyredisconnection.Connection if attr.startswith("rediss"): connection_class = pyredisconnection.SSLConnection + print(attr) + print(connection_class) urllib.parse.uses_netloc.append('redis') redis_url = urllib.parse.urlparse(config_obj) From fba19e45dd227a9e52ca0b434e535b1f7c5f2d9a Mon Sep 17 00:00:00 2001 From: dmarkey Date: Wed, 26 Aug 2020 16:11:44 +0100 Subject: [PATCH 6/7] More debugging --- mrq/context.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mrq/context.py b/mrq/context.py index e01756d3..ca8b9946 100644 --- a/mrq/context.py +++ b/mrq/context.py @@ -140,6 +140,7 @@ def versiontuple(v): import redis as pyredis import redis.connection as pyredisconnection + print(config) connection_class = pyredisconnection.Connection if attr.startswith("rediss"): @@ -149,6 +150,7 @@ def versiontuple(v): urllib.parse.uses_netloc.append('redis') redis_url = urllib.parse.urlparse(config_obj) + print(redis_url) log.info("%s: Connecting to Redis at %s..." % (attr, redis_url.hostname)) From f6bd1f36d9fa4c3abb48dee82a0312e60badceb6 Mon Sep 17 00:00:00 2001 From: dmarkey Date: Wed, 26 Aug 2020 16:13:32 +0100 Subject: [PATCH 7/7] Should work now --- mrq/context.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mrq/context.py b/mrq/context.py index ca8b9946..8f19e238 100644 --- a/mrq/context.py +++ b/mrq/context.py @@ -140,17 +140,12 @@ def versiontuple(v): import redis as pyredis import redis.connection as pyredisconnection - print(config) - - connection_class = pyredisconnection.Connection - if attr.startswith("rediss"): - connection_class = pyredisconnection.SSLConnection - print(attr) - print(connection_class) + connection_class = pyredisconnection.Connection urllib.parse.uses_netloc.append('redis') redis_url = urllib.parse.urlparse(config_obj) - print(redis_url) + if redis_url.scheme == "rediss": + connection_class = pyredisconnection.SSLConnection log.info("%s: Connecting to Redis at %s..." % (attr, redis_url.hostname))