Skip to content

Commit 1c920d4

Browse files
Relrinsamuelcolvin
authored andcommitted
Added the SSL option for RedisSettings dataclass (#165)
* Added the SSL option for RedisSettings dataclass * Updated HISTORY.rst * Fixed linter errors
1 parent 4166fdd commit 1c920d4

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ History
66
v0.18.4 (unreleased)
77
....................
88
* Add ``py.typed`` file to tell mypy the package has type hints, #163
9+
* Added the SSL option for RedisSettings dataclass
910

1011
v0.18.3 (2019-11-13)
1112
....................

arq/connections.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dataclasses import dataclass
55
from datetime import datetime, timedelta
66
from operator import attrgetter
7+
from ssl import SSLContext
78
from typing import Any, List, Optional, Tuple, Union
89
from uuid import uuid4
910

@@ -29,6 +30,7 @@ class RedisSettings:
2930
port: int = 6379
3031
database: int = 0
3132
password: str = None
33+
ssl: [bool, None, SSLContext] = None
3234
conn_timeout: int = 1
3335
conn_retries: int = 5
3436
conn_retry_delay: int = 1
@@ -183,16 +185,17 @@ async def create_pool(
183185
addr = settings.host
184186

185187
async def pool_factory(*args, **kwargs):
186-
client = await aioredis.sentinel.create_sentinel_pool(*args, **kwargs)
188+
client = await aioredis.sentinel.create_sentinel_pool(*args, ssl=settings.ssl, **kwargs)
187189
return client.master_for(settings.sentinel_master)
188190

189191
else:
190-
pool_factory = functools.partial(aioredis.create_pool, create_connection_timeout=settings.conn_timeout)
192+
pool_factory = functools.partial(
193+
aioredis.create_pool, create_connection_timeout=settings.conn_timeout, ssl=settings.ssl
194+
)
191195
addr = settings.host, settings.port
192196

193197
try:
194198
pool = await pool_factory(addr, db=settings.database, password=settings.password, encoding='utf8')
195-
196199
pool = ArqRedis(pool, job_serializer=job_serializer, job_deserializer=job_deserializer)
197200

198201
except (ConnectionError, OSError, aioredis.RedisError, asyncio.TimeoutError) as e:

tests/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_settings_changed():
1212
settings = RedisSettings(port=123)
1313
assert settings.port == 123
1414
assert (
15-
'<RedisSettings host=localhost port=123 database=0 password=None conn_timeout=1 conn_retries=5 '
15+
'<RedisSettings host=localhost port=123 database=0 password=None ssl=None conn_timeout=1 conn_retries=5 '
1616
'conn_retry_delay=1 sentinel=False sentinel_master=mymaster>'
1717
) == str(settings)
1818

0 commit comments

Comments
 (0)