{"id":1958,"library":"channels-redis","title":"channels-redis","description":"channels-redis (version 4.3.0) is a Redis-backed ASGI channel layer implementation for Django Channels. It enables real-time communication, supporting WebSockets, chat protocols, and other asynchronous features in Django applications. It is the official Django-maintained channel layer recommended for production use and is actively maintained with regular updates.","status":"active","version":"4.3.0","language":"en","source_language":"en","source_url":"https://github.com/django/channels_redis/","tags":["Django","Channels","Redis","ASGI","real-time","websockets","messaging","channel layer"],"install":[{"cmd":"pip install channels-redis","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for Redis server interaction. Minimum version 4.6.0. Redis server >= 5.0 is also a prerequisite.","package":"redis"},{"reason":"The core Django Channels library, which channels-redis extends. Minimum version 4.2.0.","package":"channels"},{"reason":"Used for message serialization. Version ~1.0.","package":"msgpack"},{"reason":"Base ASGI library. Version <4, >=3.9.","package":"asgiref"},{"reason":"Optional dependency to improve layer performance, used automatically if installed.","package":"hiredis","optional":true}],"imports":[{"note":"While older tutorials or Channels 1.x might imply a direct import from channels.layers, the correct and current import path for the Redis-backed layer is from channels_redis.core.","wrong":"from channels.layers import RedisChannelLayer","symbol":"RedisChannelLayer","correct":"from channels_redis.core import RedisChannelLayer"},{"note":"This is a newer, beta-status layer that leverages Redis Pub/Sub for message dispatch.","symbol":"RedisPubSubChannelLayer","correct":"from channels_redis.pubsub import RedisPubSubChannelLayer"}],"quickstart":{"code":"import os\nfrom django.core.asgi import get_asgi_application\nfrom channels.routing import ProtocolTypeRouter, URLRouter\nfrom channels.auth import AuthMiddlewareStack\nfrom django.conf import settings\n\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"your_project.settings\")\n\n# In your settings.py (e.g., your_project/settings.py):\n# CHANNEL_LAYERS = {\n#     \"default\": {\n#         \"BACKEND\": \"channels_redis.core.RedisChannelLayer\",\n#         \"CONFIG\": {\n#             \"hosts\": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],\n#         },\n#     },\n# }\n\n# Example routing (your_project/routing.py)\n# from django.urls import re_path\n# from chat.consumers import ChatConsumer\n# websocket_urlpatterns = [\n#     re_path(r'ws/chat/(?P<room_name>\\w+)/$', ChatConsumer.as_asgi()),\n# ]\n\napplication = ProtocolTypeRouter({\n    \"http\": get_asgi_application(),\n    \"websocket\": AuthMiddlewareStack(\n        URLRouter(\n            # Replace with your app's websocket_urlpatterns\n            # Example: chat.routing.websocket_urlpatterns\n            [] # Placeholder for actual URLRouter patterns\n        )\n    ),\n})","lang":"python","description":"To use channels-redis, you typically configure your `CHANNEL_LAYERS` setting in `settings.py` and set up your ASGI application in `asgi.py`. Ensure a Redis server (version 5.0 or higher) is running. This example shows a basic setup for the default `RedisChannelLayer` and a structure for `asgi.py`. You would further define `websocket_urlpatterns` in your app's `routing.py` and include it in the `URLRouter`."},"warnings":[{"fix":"Update `CHANNEL_LAYERS['default']['CONFIG']['hosts']` to use URI strings (e.g., 'redis://localhost:6379') or dicts with an 'address' key. Ensure `redis-py` is at least 4.5.3.","message":"Version 4.0.0 migrated from `aioredis` to `redis-py`. This changed the configuration for `hosts`; specifying hosts as tuples is no longer supported, and for dicts, only the `address` key is considered. Pass `password` inline in the URI.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"For Channels 2.x and newer, install and use `channels-redis` instead of `asgi_redis`.","message":"The `asgi_redis` package is an older name for channels-redis and is intended for Channels 1.x projects. Do not use it for Channels 2.x+ projects.","severity":"deprecated","affected_versions":"<2.0.0"},{"message":"The `RedisPubSubChannelLayer` is currently in Beta status. This means it may be subject to breaking changes as it matures. Use with caution in production environments where stability is paramount.","severity":"gotcha"},{"fix":"Ensure your project uses Python 3.9+ and Django 4.2.2+ to be compatible with channels-redis 4.3.0. Refer to specific changelogs for minimum version requirements for other 4.x releases.","message":"Channels-redis 4.x dropped support for older Python and Django versions. Python 3.8 support was dropped in 4.3.0, and Python 3.7 was dropped in 4.2.0. Minimum Django version is 4.2.2 for `channels-redis` 4.3.0.","severity":"breaking","affected_versions":"4.x"},{"fix":"Implement explicit connection closing mechanisms where `async_to_sync` is used, especially if managing custom connection pools or unusual application lifecycles.","message":"When using `async_to_sync()` with `redis-py 4.x`, ensure that Redis connections are manually closed when an event loop shuts down to avoid warnings or resource leaks. This was addressed for the pub-sub layer in 4.1.0 but remains a general consideration.","severity":"gotcha","affected_versions":"4.0.0+"},{"fix":"Plan your Redis sharding configuration carefully and avoid frequent changes to the `hosts` list in production. Ensure consistent configuration across all application instances.","message":"When using sharding, passing multiple hosts to `CONFIG['hosts']` enables sharding. However, changing this host list can lead to loss of some sharded data. All servers talking to the same layer should have the same prefix and host list.","severity":"gotcha","affected_versions":"All versions with sharding"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}