Skip to content

Commit

Permalink
Merge pull request #23 from Sefaria/redis-pw
Browse files Browse the repository at this point in the history
fix: add redis password when it exists
  • Loading branch information
nsantacruz authored Mar 4, 2024
2 parents 2bfd28d + d7d5c2a commit 03794f0
Showing 1 changed file with 10 additions and 2 deletions.
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)

0 comments on commit 03794f0

Please sign in to comment.