redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

[Async] Cannot use pubsub when having password enabled

Open Luc1412 opened this issue 2 years ago • 1 comments

Version: 4.4.0

Platform: Windows 11, MacOS 12

Description: When passing a password into the connection string, normal redis usage works fine, however using pubsub subscribe causing redis.exceptions.ConnectionError: Error 11001 connecting to xxw0:6379. 11001.

redis = await Redis.from_url(
    format_redis_uri(
        host=self._config.get('database.redis.host'),
        port=self._config.get('database.redis.port'),
        password=self._config.get('database.redis.password')
    ), decode_responses=True 
)

channel = self._redis.pubsub()
await channel.subscribe(self._config.get('database.redis.shard_communication_channel')) # <- Causing the error

def format_redis_uri(host, **kwargs):
    base = 'redis://'
    if kwargs.get('username') and kwargs.get('password'):
        base += f'{kwargs["username"]}:'
    if kwargs.get('password'):
        base += f'{kwargs["password"]}@'
    base += host
    if kwargs.get('port'):
        base += f':{kwargs["port"]}'
    if kwargs.get('database'):
        base += f'/{kwargs["database"]}'
    return base

I also disabled password auth on my redis instance. The error still remains until I remove the password.

Luc1412 avatar Jan 05 '23 09:01 Luc1412