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

the original aioredis supports UNIX socket why not us? #209

Closed
wants to merge 9 commits into from
Closed
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
11 changes: 4 additions & 7 deletions arq/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class RedisSettings:
Used by :func:`arq.connections.create_pool` and :class:`arq.worker.Worker`.
"""

host: Union[str, List[Tuple[str, int]]] = 'localhost'
port: int = 6379
address: Union[str, Tuple[str, int], List[Tuple[str, int]]] = ('localhost', 6379)
database: int = 0
password: Optional[str] = None
ssl: Union[bool, None, SSLContext] = None
Expand Down Expand Up @@ -186,11 +185,10 @@ async def create_pool(
settings: RedisSettings = RedisSettings() if settings_ is None else settings_

assert not (
type(settings.host) is str and settings.sentinel
type(settings.address) is not list and settings.sentinel
), "str provided for 'host' but 'sentinel' is true; list of sentinels expected"

if settings.sentinel:
addr: Any = settings.host

async def pool_factory(*args: Any, **kwargs: Any) -> Redis:
client = await aioredis.sentinel.create_sentinel_pool(*args, ssl=settings.ssl, **kwargs)
Expand All @@ -200,10 +198,9 @@ async def pool_factory(*args: Any, **kwargs: Any) -> Redis:
pool_factory = functools.partial(
aioredis.create_pool, create_connection_timeout=settings.conn_timeout, ssl=settings.ssl
)
addr = settings.host, settings.port

try:
pool = await pool_factory(addr, db=settings.database, password=settings.password, encoding='utf8')
pool = await pool_factory(settings.address, db=settings.database, password=settings.password, encoding='utf8')
pool = ArqRedis(
pool,
job_serializer=job_serializer,
Expand All @@ -215,7 +212,7 @@ async def pool_factory(*args: Any, **kwargs: Any) -> Redis:
if retry < settings.conn_retries:
logger.warning(
'redis connection error %s %s %s, %d retries remaining...',
addr,
settings.address,
e.__class__.__name__,
e,
settings.conn_retries - retry,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@


def test_settings_changed():
settings = RedisSettings(port=123)
assert settings.port == 123
settings = RedisSettings(password='123')
assert settings.password == '123'
assert (
'<RedisSettings host=localhost port=123 database=0 password=None ssl=None conn_timeout=1 conn_retries=5 '
"<RedisSettings address=('localhost', 6379) database=0 password=123 ssl=None conn_timeout=1 conn_retries=5 "
'conn_retry_delay=1 sentinel=False sentinel_master=mymaster>'
) == str(settings)


async def test_redis_timeout(mocker, create_pool):
mocker.spy(arq.utils.asyncio, 'sleep')
with pytest.raises(OSError):
await create_pool(RedisSettings(port=0, conn_retry_delay=0))
await create_pool(RedisSettings(address=('localhost', 0), conn_retry_delay=0))
assert arq.utils.asyncio.sleep.call_count == 5


Expand All @@ -30,7 +30,7 @@ async def test_redis_sentinel_failure(create_pool):
FIXME: this is currently causing 3 "Task was destroyed but it is pending!" warnings
"""
settings = RedisSettings()
settings.host = [('localhost', 6379), ('localhost', 6379)]
settings.address = [('localhost', 6379), ('localhost', 6379)]
settings.sentinel = True
try:
pool = await create_pool(settings)
Expand Down