add: redis username to the settings

This commit is contained in:
Mert Can Alici 2024-08-28 16:57:06 +02:00
parent d5e55ab95a
commit d5f99fc8e6
No known key found for this signature in database
2 changed files with 6 additions and 3 deletions

View File

@ -75,6 +75,7 @@ def get_redis_from_config(settings, connection_class=Redis):
'host': settings.get('REDIS_HOST', 'localhost'),
'port': settings.get('REDIS_PORT', 6379),
'db': settings.get('REDIS_DB', 0),
'username': settings.get('REDIS_USERNAME', None),
'password': settings.get('REDIS_PASSWORD', None),
'ssl': ssl,
'ssl_ca_certs': settings.get('REDIS_SSL_CA_CERTS', None),

View File

@ -17,18 +17,20 @@ class TestHelpers(RQTestCase):
self.assertEqual(connection_kwargs['port'], 1)
settings = {
'REDIS_URL': 'redis://localhost:1/1',
'REDIS_HOST': 'foo',
'REDIS_DB': 2,
'REDIS_PORT': 2,
'REDIS_USERNAME': 'foo',
'REDIS_PASSWORD': 'bar',
}
# Ensure REDIS_URL is preferred
redis = get_redis_from_config(settings)
connection_kwargs = redis.connection_pool.connection_kwargs
self.assertEqual(connection_kwargs['db'], 1)
self.assertEqual(connection_kwargs['port'], 1)
self.assertEqual(connection_kwargs['db'], 2)
self.assertEqual(connection_kwargs['port'], 2)
self.assertEqual(connection_kwargs['username'], 'foo')
self.assertEqual(connection_kwargs['password'], 'bar')
# Ensure fall back to regular connection parameters
settings['REDIS_URL'] = None