Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Sentinel authentication #690

Closed
simsicon opened this issue Jan 16, 2020 · 2 comments
Closed

Sentinel authentication #690

simsicon opened this issue Jan 16, 2020 · 2 comments
Labels
resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.

Comments

@simsicon
Copy link

Redis supports sentinel authentication since 5.0.1.

When I use aioredis.create_sentinel to initialize a sentinel instance, the password arg is for redis backends, not for sentinel password.

redis-py provides sentinel_kwargs to pass the arg to sentinel.

Is there a similar way to do that? Or how can I quick fix this? Thanks.

@mohammadhzp
Copy link

I just ran into the issue and as a quick fix I did this:

from async_timeout import timeout as async_timeout
import asyncio
import aioredis
import aioredis.log


class MySentinelPool(aioredis.sentinel.SentinelPool):
    def __init__(self, *args, **kwargs):
        try:
            self.sentinel_password = kwargs['sentinel_password']
        except KeyError:
            self.sentinel_password = None
        else:
            del kwargs['sentinel_password']

        super().__init__(*args, **kwargs)

    async def _connect_sentinel(self, address, timeout, pools):
        try:
            with async_timeout(timeout):
                pool = await aioredis.pool.create_pool(
                    address, minsize=1, maxsize=2,
                    parser=self._parser_class, password=self.sentinel_password
                )
            pools.append(pool)
            return pool
        except asyncio.TimeoutError as err:
            aioredis.log.sentinel_logger.debug(
                "Failed to connect to Sentinel(%r) within %ss timeout",
                address, timeout)
            return err
        except Exception as err:
            aioredis.log.sentinel_logger.debug(
                "Error connecting to Sentinel(%r): %r", address, err)
            return err

@seandstewart
Copy link
Collaborator

This issue should be resolved as of #891 - please feel free to pull in the latest master and test to ensure this is the case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.
Projects
None yet
Development

No branches or pull requests

3 participants