Skip to content

Commit 63c84e6

Browse files
Romain Fliedelr0ro
Romain Fliedel
authored andcommitted
Fix BlockingConnectionPool.from_url parsing of timeout in query args #2983
1 parent 5391c5f commit 63c84e6

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

redis/asyncio/connection.py

+1
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ def to_bool(value) -> Optional[bool]:
861861
"max_connections": int,
862862
"health_check_interval": int,
863863
"ssl_check_hostname": to_bool,
864+
"timeout": float,
864865
}
865866
)
866867

redis/connection.py

+1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ def to_bool(value):
853853
"max_connections": int,
854854
"health_check_interval": int,
855855
"ssl_check_hostname": to_bool,
856+
"timeout": float,
856857
}
857858

858859

tests/test_asyncio/test_connection_pool.py

+25
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,31 @@ def test_invalid_scheme_raises_error(self):
454454
)
455455

456456

457+
class TestBlockingConnectionPoolURLParsing:
458+
def test_extra_typed_querystring_options(self):
459+
pool = redis.BlockingConnectionPool.from_url(
460+
"redis://localhost/2?socket_timeout=20&socket_connect_timeout=10"
461+
"&socket_keepalive=&retry_on_timeout=Yes&max_connections=10&timeout=13.37"
462+
)
463+
464+
assert pool.connection_class == redis.Connection
465+
assert pool.connection_kwargs == {
466+
"host": "localhost",
467+
"db": 2,
468+
"socket_timeout": 20.0,
469+
"socket_connect_timeout": 10.0,
470+
"retry_on_timeout": True,
471+
}
472+
assert pool.max_connections == 10
473+
assert pool.timeout == 13.37
474+
475+
def test_invalid_extra_typed_querystring_options(self):
476+
with pytest.raises(ValueError):
477+
redis.BlockingConnectionPool.from_url(
478+
"redis://localhost/2?timeout=_not_a_float_"
479+
)
480+
481+
457482
class TestConnectionPoolUnixSocketURLParsing:
458483
def test_defaults(self):
459484
pool = redis.ConnectionPool.from_url("unix:///socket")

tests/test_connection_pool.py

+25
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,31 @@ def test_invalid_scheme_raises_error_when_double_slash_missing(self):
359359
)
360360

361361

362+
class TestBlockingConnectionPoolURLParsing:
363+
def test_extra_typed_querystring_options(self):
364+
pool = redis.BlockingConnectionPool.from_url(
365+
"redis://localhost/2?socket_timeout=20&socket_connect_timeout=10"
366+
"&socket_keepalive=&retry_on_timeout=Yes&max_connections=10&timeout=42"
367+
)
368+
369+
assert pool.connection_class == redis.Connection
370+
assert pool.connection_kwargs == {
371+
"host": "localhost",
372+
"db": 2,
373+
"socket_timeout": 20.0,
374+
"socket_connect_timeout": 10.0,
375+
"retry_on_timeout": True,
376+
}
377+
assert pool.max_connections == 10
378+
assert pool.timeout == 42.0
379+
380+
def test_invalid_extra_typed_querystring_options(self):
381+
with pytest.raises(ValueError):
382+
redis.BlockingConnectionPool.from_url(
383+
"redis://localhost/2?timeout=_not_a_float_"
384+
)
385+
386+
362387
class TestConnectionPoolUnixSocketURLParsing:
363388
def test_defaults(self):
364389
pool = redis.ConnectionPool.from_url("unix:///socket")

0 commit comments

Comments
 (0)