From 3638e1884448403e0f8db915b6ef0c3d3b0688ac Mon Sep 17 00:00:00 2001 From: Jade Meskill Date: Wed, 12 Jan 2022 19:44:11 -0700 Subject: [PATCH 1/3] add support for different redis db --- bookwyrm/management/commands/erase_streams.py | 2 +- bookwyrm/redis_store.py | 2 +- bookwyrm/settings.py | 3 ++- celerywyrm/settings.py | 5 +++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bookwyrm/management/commands/erase_streams.py b/bookwyrm/management/commands/erase_streams.py index 1d34b1bb6..cb732079d 100644 --- a/bookwyrm/management/commands/erase_streams.py +++ b/bookwyrm/management/commands/erase_streams.py @@ -5,7 +5,7 @@ import redis from bookwyrm import settings r = redis.Redis( - host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, db=0 + host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, db=settings.REDIS_ACTIVITY_DB ) diff --git a/bookwyrm/redis_store.py b/bookwyrm/redis_store.py index 964409e89..560527c92 100644 --- a/bookwyrm/redis_store.py +++ b/bookwyrm/redis_store.py @@ -8,7 +8,7 @@ r = redis.Redis( host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, password=settings.REDIS_ACTIVITY_PASSWORD, - db=0, + db=settings.REDIS_ACTIVITY_DB, ) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 92ff7ecdd..22717f783 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -113,6 +113,7 @@ WSGI_APPLICATION = "bookwyrm.wsgi.application" REDIS_ACTIVITY_HOST = env("REDIS_ACTIVITY_HOST", "localhost") REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379) REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None) +REDIS_ACTIVITY_DB = env("REDIS_ACTIVITY_DB", 0) MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200)) @@ -139,7 +140,7 @@ else: CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/0", + "LOCATION": f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/{REDIS_ACTIVITY_DB}", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", }, diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py index 24729345b..7016d4aa1 100644 --- a/celerywyrm/settings.py +++ b/celerywyrm/settings.py @@ -6,12 +6,13 @@ from bookwyrm.settings import * REDIS_BROKER_PASSWORD = requests.utils.quote(env("REDIS_BROKER_PASSWORD", None)) REDIS_BROKER_HOST = env("REDIS_BROKER_HOST", "redis_broker") REDIS_BROKER_PORT = env("REDIS_BROKER_PORT", 6379) +REDIS_BROKER_DB = env("REDIS_BROKER_DB", 0) CELERY_BROKER_URL = ( - f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/0" + f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" ) CELERY_RESULT_BACKEND = ( - f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/0" + f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" ) CELERY_DEFAULT_QUEUE = "low_priority" From 5a3d108c6211d83269ab0e3224f079bd96250b81 Mon Sep 17 00:00:00 2001 From: Jade Meskill Date: Wed, 12 Jan 2022 22:46:51 -0700 Subject: [PATCH 2/3] update fomatting to pass automated checks --- bookwyrm/management/commands/erase_streams.py | 4 +++- celerywyrm/settings.py | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bookwyrm/management/commands/erase_streams.py b/bookwyrm/management/commands/erase_streams.py index cb732079d..ed9987c49 100644 --- a/bookwyrm/management/commands/erase_streams.py +++ b/bookwyrm/management/commands/erase_streams.py @@ -5,7 +5,9 @@ import redis from bookwyrm import settings r = redis.Redis( - host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, db=settings.REDIS_ACTIVITY_DB + host=settings.REDIS_ACTIVITY_HOST, + port=settings.REDIS_ACTIVITY_PORT, + db=settings.REDIS_ACTIVITY_DB, ) diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py index 7016d4aa1..11f3acf45 100644 --- a/celerywyrm/settings.py +++ b/celerywyrm/settings.py @@ -8,12 +8,8 @@ REDIS_BROKER_HOST = env("REDIS_BROKER_HOST", "redis_broker") REDIS_BROKER_PORT = env("REDIS_BROKER_PORT", 6379) REDIS_BROKER_DB = env("REDIS_BROKER_DB", 0) -CELERY_BROKER_URL = ( - f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" -) -CELERY_RESULT_BACKEND = ( - f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" -) +CELERY_BROKER_URL = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" +CELERY_RESULT_BACKEND = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" CELERY_DEFAULT_QUEUE = "low_priority" From 900937ee5f1d4a63191ecc9994351eea8e888f47 Mon Sep 17 00:00:00 2001 From: Jade Meskill Date: Thu, 13 Jan 2022 09:15:24 -0700 Subject: [PATCH 3/3] use REDIS_x_DB_INDEX instead of REDIS_x_DB, add optional setting to example env file --- .env.example | 4 ++++ bookwyrm/management/commands/erase_streams.py | 2 +- bookwyrm/redis_store.py | 2 +- bookwyrm/settings.py | 4 ++-- celerywyrm/settings.py | 6 +++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 3c935287e..2000a7165 100644 --- a/.env.example +++ b/.env.example @@ -28,10 +28,14 @@ MAX_STREAM_LENGTH=200 REDIS_ACTIVITY_HOST=redis_activity REDIS_ACTIVITY_PORT=6379 REDIS_ACTIVITY_PASSWORD=redispassword345 +# Optional, use a different redis database (defaults to 0) +# REDIS_ACTIVITY_DB_INDEX=0 # Redis as celery broker REDIS_BROKER_PORT=6379 REDIS_BROKER_PASSWORD=redispassword123 +# Optional, use a different redis database (defaults to 0) +# REDIS_BROKER_DB_INDEX=0 # Monitoring for celery FLOWER_PORT=8888 diff --git a/bookwyrm/management/commands/erase_streams.py b/bookwyrm/management/commands/erase_streams.py index ed9987c49..7b8074029 100644 --- a/bookwyrm/management/commands/erase_streams.py +++ b/bookwyrm/management/commands/erase_streams.py @@ -7,7 +7,7 @@ from bookwyrm import settings r = redis.Redis( host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, - db=settings.REDIS_ACTIVITY_DB, + db=settings.REDIS_ACTIVITY_DB_INDEX, ) diff --git a/bookwyrm/redis_store.py b/bookwyrm/redis_store.py index 560527c92..ae50db2ee 100644 --- a/bookwyrm/redis_store.py +++ b/bookwyrm/redis_store.py @@ -8,7 +8,7 @@ r = redis.Redis( host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, password=settings.REDIS_ACTIVITY_PASSWORD, - db=settings.REDIS_ACTIVITY_DB, + db=settings.REDIS_ACTIVITY_DB_INDEX, ) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 22717f783..a91630efa 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -113,7 +113,7 @@ WSGI_APPLICATION = "bookwyrm.wsgi.application" REDIS_ACTIVITY_HOST = env("REDIS_ACTIVITY_HOST", "localhost") REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379) REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None) -REDIS_ACTIVITY_DB = env("REDIS_ACTIVITY_DB", 0) +REDIS_ACTIVITY_DB_INDEX = env("REDIS_ACTIVITY_DB_INDEX", 0) MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200)) @@ -140,7 +140,7 @@ else: CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/{REDIS_ACTIVITY_DB}", + "LOCATION": f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/{REDIS_ACTIVITY_DB_INDEX}", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", }, diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py index 11f3acf45..bd7805e51 100644 --- a/celerywyrm/settings.py +++ b/celerywyrm/settings.py @@ -6,10 +6,10 @@ from bookwyrm.settings import * REDIS_BROKER_PASSWORD = requests.utils.quote(env("REDIS_BROKER_PASSWORD", None)) REDIS_BROKER_HOST = env("REDIS_BROKER_HOST", "redis_broker") REDIS_BROKER_PORT = env("REDIS_BROKER_PORT", 6379) -REDIS_BROKER_DB = env("REDIS_BROKER_DB", 0) +REDIS_BROKER_DB_INDEX = env("REDIS_BROKER_DB_INDEX", 0) -CELERY_BROKER_URL = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" -CELERY_RESULT_BACKEND = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB}" +CELERY_BROKER_URL = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB_INDEX}" +CELERY_RESULT_BACKEND = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB_INDEX}" CELERY_DEFAULT_QUEUE = "low_priority"