From 604846061074b6df1e43b579cb948c4cc803394f Mon Sep 17 00:00:00 2001 From: brian-goo Date: Sun, 28 Jul 2024 17:23:11 +0900 Subject: [PATCH] Allow connection_pool to be set in RedisSettings --- arq/connections.py | 2 ++ tests/test_utils.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arq/connections.py b/arq/connections.py index c1058890..ac60f3f3 100644 --- a/arq/connections.py +++ b/arq/connections.py @@ -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 @@ -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, diff --git a/tests/test_utils.py b/tests/test_utils.py index 96c9a25c..165b04f1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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, " "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', " @@ -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, @@ -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',