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 connections.py: allow to connect to Redis using a Unix socket URL… #392

Merged
merged 3 commits into from
Apr 1, 2024
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
4 changes: 3 additions & 1 deletion arq/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def from_dsn(cls, dsn: str) -> 'RedisSettings':
if query_db:
# e.g. redis://localhost:6379?db=1
database = int(query_db[0])
else:
elif conf.scheme != 'unix':
database = int(conf.path.lstrip('/')) if conf.path else 0
else:
database = 0
return RedisSettings(
host=conf.hostname or 'localhost',
port=conf.port or 6379,
Expand Down
56 changes: 56 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import re
import sys
from dataclasses import asdict
from datetime import timedelta

import pytest
Expand Down Expand Up @@ -197,3 +198,58 @@ def test_import_string_invalid_short():
def test_import_string_invalid_missing():
with pytest.raises(ImportError, match='Module "math" does not define a "foobar" attribute'):
arq.utils.import_string('math.foobar')


def test_settings_plain():
settings = RedisSettings()
assert asdict(settings) == {
'host': 'localhost',
'port': 6379,
'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,
'sentinel': False,
'sentinel_master': 'mymaster',
'retry_on_timeout': False,
'retry_on_error': None,
'retry': None,
}


def test_settings_from_socket_dsn():
settings = RedisSettings.from_dsn('unix:///run/redis/redis.sock')
# insert_assert(asdict(settings))
assert asdict(settings) == {
'host': 'localhost',
'port': 6379,
'unix_socket_path': '/run/redis/redis.sock',
'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,
'sentinel': False,
'sentinel_master': 'mymaster',
'retry_on_timeout': False,
'retry_on_error': None,
'retry': None,
}