Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BlockingConnectionPool.from_url parsing of timeout in query args #2983 #2984

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ def to_bool(value) -> Optional[bool]:
"max_connections": int,
"health_check_interval": int,
"ssl_check_hostname": to_bool,
"timeout": float,
}
)

Expand Down
1 change: 1 addition & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ def to_bool(value):
"max_connections": int,
"health_check_interval": int,
"ssl_check_hostname": to_bool,
"timeout": float,
}


Expand Down
25 changes: 25 additions & 0 deletions tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,31 @@ def test_invalid_scheme_raises_error(self):
)


class TestBlockingConnectionPoolURLParsing:
def test_extra_typed_querystring_options(self):
pool = redis.BlockingConnectionPool.from_url(
"redis://localhost/2?socket_timeout=20&socket_connect_timeout=10"
"&socket_keepalive=&retry_on_timeout=Yes&max_connections=10&timeout=13.37"
)

assert pool.connection_class == redis.Connection
assert pool.connection_kwargs == {
"host": "localhost",
"db": 2,
"socket_timeout": 20.0,
"socket_connect_timeout": 10.0,
"retry_on_timeout": True,
}
assert pool.max_connections == 10
assert pool.timeout == 13.37

def test_invalid_extra_typed_querystring_options(self):
with pytest.raises(ValueError):
redis.BlockingConnectionPool.from_url(
"redis://localhost/2?timeout=_not_a_float_"
)


class TestConnectionPoolUnixSocketURLParsing:
def test_defaults(self):
pool = redis.ConnectionPool.from_url("unix:///socket")
Expand Down
25 changes: 25 additions & 0 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,31 @@ def test_invalid_scheme_raises_error_when_double_slash_missing(self):
)


class TestBlockingConnectionPoolURLParsing:
def test_extra_typed_querystring_options(self):
pool = redis.BlockingConnectionPool.from_url(
"redis://localhost/2?socket_timeout=20&socket_connect_timeout=10"
"&socket_keepalive=&retry_on_timeout=Yes&max_connections=10&timeout=42"
)

assert pool.connection_class == redis.Connection
assert pool.connection_kwargs == {
"host": "localhost",
"db": 2,
"socket_timeout": 20.0,
"socket_connect_timeout": 10.0,
"retry_on_timeout": True,
}
assert pool.max_connections == 10
assert pool.timeout == 42.0

def test_invalid_extra_typed_querystring_options(self):
with pytest.raises(ValueError):
redis.BlockingConnectionPool.from_url(
"redis://localhost/2?timeout=_not_a_float_"
)


class TestConnectionPoolUnixSocketURLParsing:
def test_defaults(self):
pool = redis.ConnectionPool.from_url("unix:///socket")
Expand Down
Loading