Skip to content

Commit

Permalink
support dsn
Browse files Browse the repository at this point in the history
  • Loading branch information
aamalev committed Dec 12, 2019
1 parent 3afb973 commit b6da531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aioworkers_redis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def set_config(self, config):
cfg = config.new_parent(logger='aioworkers_redis')
c = cfg.get('connection')
if not isinstance(c, str):
pass
if cfg.get('dsn'):
cfg = cfg.new_child(connection=dict(dsn=cfg.get('dsn')))
elif c.startswith('redis://'):
cfg = cfg.new_child(connection=dict(uri=c))
cfg = cfg.new_child(connection=dict(dsn=c))
elif not c.startswith('.'):
raise ValueError('Connector link must be startswith point .%s' % c)
super().set_config(cfg)
Expand Down Expand Up @@ -112,8 +113,8 @@ async def connect(self):
self._pool = await self.pool_factory(cfg)

async def pool_factory(self, cfg: dict) -> Optional[aioredis.Redis]:
if cfg.get('uri'):
address = cfg.pop('uri')
if cfg.get('dsn'):
address = cfg.pop('dsn')
elif cfg.get('address'):
address = cfg.pop('address')
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ async def test_connect(context):
assert context.connector.clean_key('a:3') == '3'


async def test_dsn(config):
config.update({
'connector.dsn': 'redis://localhost',
'connector.name': 'connector',
})
cls = import_name(config.connector.cls)
async with cls(config.connector) as c:
assert c.connector


async def test_uri(config):
config.update({
'connector.connection': 'redis://localhost',
Expand Down

0 comments on commit b6da531

Please sign in to comment.