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

Allow connection_pool to be set in RedisSettings #473

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions arq/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RedisSettings:
Used by :func:`arq.connections.create_pool` and :class:`arq.worker.Worker`.
"""

connection_pool: Optional[ConnectionPool] = None
host: Union[str, List[Tuple[str, int]]] = 'localhost'
port: int = 6379
unix_socket_path: Optional[str] = None
Expand Down Expand Up @@ -251,6 +252,7 @@ def pool_factory(*args: Any, **kwargs: Any) -> ArqRedis:
else:
pool_factory = functools.partial(
ArqRedis,
pool_or_conn=settings.connection_pool,
host=settings.host,
port=settings.port,
unix_socket_path=settings.unix_socket_path,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_settings_changed():
settings = RedisSettings(port=123)
assert settings.port == 123
assert (
"RedisSettings(host='localhost', port=123, unix_socket_path=None, database=0, username=None, password=None, "
"RedisSettings(connection_pool=None, host='localhost', port=123, unix_socket_path=None, database=0, username=None, password=None, "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth adding a test where the connectionpool is set

"ssl=False, ssl_keyfile=None, ssl_certfile=None, ssl_cert_reqs='required', ssl_ca_certs=None, "
'ssl_ca_data=None, ssl_check_hostname=False, conn_timeout=1, conn_retries=5, conn_retry_delay=1, '
"max_connections=None, sentinel=False, sentinel_master='mymaster', "
Expand Down Expand Up @@ -203,6 +203,7 @@ def test_import_string_invalid_missing():
def test_settings_plain():
settings = RedisSettings()
assert asdict(settings) == {
'connection_pool': None,
'host': 'localhost',
'port': 6379,
'unix_socket_path': None,
Expand Down Expand Up @@ -232,6 +233,7 @@ def test_settings_from_socket_dsn():
settings = RedisSettings.from_dsn('unix:///run/redis/redis.sock')
# insert_assert(asdict(settings))
assert asdict(settings) == {
'connection_pool': None,
'host': 'localhost',
'port': 6379,
'unix_socket_path': '/run/redis/redis.sock',
Expand Down