Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass USERNAME to Redis connection_kwargs #656

Open
joachimBurket opened this issue Mar 2, 2023 · 0 comments · May be fixed by #657
Open

Pass USERNAME to Redis connection_kwargs #656

joachimBurket opened this issue Mar 2, 2023 · 0 comments · May be fixed by #657

Comments

@joachimBurket
Copy link

joachimBurket commented Mar 2, 2023

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.

@joachimBurket joachimBurket linked a pull request Mar 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant