Skip to content

Pass USERNAME to Redis connection_kwargs #656

Open
@joachimBurket

Description

@joachimBurket

Problem Statement
The username defined in the cache options is not passed to the connection kwargs.

I'm connecting to a Sentinel cluster with the following cache parameters:

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://redis6.local/0',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.SentinelClient',
            'USERNAME': 'my-redis-user',
            'PASSWORD': 'my-very-long-redis-password',
            'SENTINEL_KWARGS': {
                'username': 'my-sentinel-user',
                'password': 'my-very-long-sentinel-password',
            },
            'SENTINELS': [
                ('redis6a.local', 26379), ('redis6b.local', 26379), ('redis6c.local', 26379)
            ],
        }
    }
}

So the SentinelConnectionFactory is used.

The SENTINEL_KWARGS are passed to the Sentinel objects, but the USERNAME is not passed to the connection_kwargs param.

Describe the solution you'd like
The make_connection_params() method should get the USERNAME from the options.

def make_connection_params(self, url):

    kwargs = {
        "url": url,
        "parser_class": self.get_parser_cls(),
    }

    # ADD THIS
    username = self.options.get("USERNAME", None)
    if username:
        kwargs["username"] = username

    password = self.options.get("PASSWORD", None)
    if password:
        kwargs["password"] = password

    # [...]

    return kwargs

I'm not sure if there are other cases where the USERNAME should be passed to the Sentinel or Redis objects. Maybe in the ConnectionFactory's get_connection_pool() method?

I can start a merge request with that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions