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

fix: add redis password when it exists #23

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/celery_setup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
# Either define SENTINEL_HEADLESS_URL if using sentinel or REDIS_URL for a simple redis instance
sentinel_url = os.getenv('SENTINEL_HEADLESS_URL')
redis_url = os.getenv('REDIS_URL')
redis_password = os.getenv('REDIS_PASSWORD')


def add_db_num_to_url(url, db_num):
return url.replace(f':{redis_port}', f':{redis_port}/{db_num}')


def add_password_to_url(url, password):
if len(password) == 0:
return url
return url.replace('redis://', f'redis://:{password}@')


if sentinel_url:
redisdns = dns.resolver.resolve(sentinel_url, 'A')
addressstring = []
Expand All @@ -28,5 +35,6 @@ def add_db_num_to_url(url, db_num):
result_backend_transport_options = {}
broker_transport_options = {}
else:
broker_url = add_db_num_to_url(f"{redis_url}:{redis_port}", broker_db_num)
result_backend = add_db_num_to_url(f"{redis_url}:{redis_port}", result_backend_db_num)
redis_url = add_password_to_url(f"{redis_url}:{redis_port}", redis_password)
broker_url = add_db_num_to_url(redis_url, broker_db_num)
result_backend = add_db_num_to_url(redis_url, result_backend_db_num)
Loading