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

Allow disabling redis #785

Open
wants to merge 3 commits into
base: htmx
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions changelog.d/+disable-redis-setting.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added ARGUS_DISABLE_REDIS setting as an environment variable to disable redis during development
and testing
27 changes: 19 additions & 8 deletions src/argus/site/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,27 @@

ASGI_APPLICATION = "argus.ws.asgi.application"

# Disable using Redis in Channels and fall back to an InMemoryChannel
# WARNING: This should only ever be used during development/testing and never
# in production. To enforce this it is only ever activated when DEBUG is also set
# fmt: off
_REDIS = urlsplit("//" + get_str_env("ARGUS_REDIS_SERVER", "127.0.0.1:6379"))
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [(_REDIS.hostname, _REDIS.port or 6379)],
ARGUS_DISABLE_REDIS = get_bool_env("ARGUS_DISABLE_REDIS", False)
if ARGUS_DISABLE_REDIS and DEBUG:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer",
},
},
}
}
else:
_REDIS = urlsplit("//" + get_str_env("ARGUS_REDIS_SERVER", "127.0.0.1:6379"))
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [(_REDIS.hostname, _REDIS.port or 6379)],
},
},
}
# fmt: on

# Project specific settings
Expand Down
Loading