Skip to content

Commit d4a9825

Browse files
author
Maksim Novikov
authored
Allow overriding connection class via keyword arguments (#1752)
1 parent 1a59a7a commit d4a9825

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

redis/connection.py

+4
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,10 @@ class initializer. In the case of conflicting arguments, querystring
11311131
arguments always win.
11321132
"""
11331133
url_options = parse_url(url)
1134+
1135+
if "connection_class" in kwargs:
1136+
url_options["connection_class"] = kwargs["connection_class"]
1137+
11341138
kwargs.update(url_options)
11351139
return cls(**kwargs)
11361140

tests/test_connection_pool.py

+18
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,15 @@ def test_extra_querystring_options(self):
445445
assert pool.connection_class == redis.UnixDomainSocketConnection
446446
assert pool.connection_kwargs == {"path": "/socket", "a": "1", "b": "2"}
447447

448+
def test_connection_class_override(self):
449+
class MyConnection(redis.UnixDomainSocketConnection):
450+
pass
451+
452+
pool = redis.ConnectionPool.from_url(
453+
'unix:///socket', connection_class=MyConnection
454+
)
455+
assert pool.connection_class == MyConnection
456+
448457

449458
@pytest.mark.skipif(not ssl_available, reason="SSL not installed")
450459
class TestSSLConnectionURLParsing:
@@ -455,6 +464,15 @@ def test_host(self):
455464
"host": "my.host",
456465
}
457466

467+
def test_connection_class_override(self):
468+
class MyConnection(redis.SSLConnection):
469+
pass
470+
471+
pool = redis.ConnectionPool.from_url(
472+
'rediss://my.host', connection_class=MyConnection
473+
)
474+
assert pool.connection_class == MyConnection
475+
458476
def test_cert_reqs_options(self):
459477
import ssl
460478

0 commit comments

Comments
 (0)