diff --git a/rq/cli/helpers.py b/rq/cli/helpers.py index db924520..dda1861e 100644 --- a/rq/cli/helpers.py +++ b/rq/cli/helpers.py @@ -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), diff --git a/tests/test_helpers.py b/tests/test_helpers.py index c351b77c..a939a7d6 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -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