From 47e128f9caded76acf05c874cd62dde448668a50 Mon Sep 17 00:00:00 2001 From: Lewis_yan Date: Thu, 9 Apr 2026 20:42:16 +0800 Subject: [PATCH] feat(channel): switch CHANNEL_LAYERS from InMemory to Redis Enable Redis-backed channel layer for production use with channels_redis, using environment-configured Redis credentials. --- backend/application/settings.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/application/settings.py b/backend/application/settings.py index 8fc6e8d..db5f5c5 100644 --- a/backend/application/settings.py +++ b/backend/application/settings.py @@ -205,15 +205,15 @@ CORS_ALLOW_CREDENTIALS = True # 指明在跨域访问中,后端是否支持 # ********************* channels配置 ******************* # # ===================================================== # ASGI_APPLICATION = "application.asgi.application" -CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}} -# CHANNEL_LAYERS = { -# 'default': { -# 'BACKEND': 'channels_redis.core.RedisChannelLayer', -# 'CONFIG': { -# "hosts": [('127.0.0.1', 6379)], #需修改 -# }, -# }, -# } +# CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}} +CHANNEL_LAYERS = { + 'default': { + 'BACKEND': 'channels_redis.core.RedisChannelLayer', + 'CONFIG': { + "hosts": [f'redis://:{REDIS_PASSWORD or ""}@{REDIS_HOST}:6379/{REDIS_DB}'], + }, + }, +} # ================================================= #