python - Django channel 不会使用 CHANNEL_LAYERS 启动 redis 服务器

标签 python django redis channels

我正在尝试复制 Mikhail Andreev 与此处发布的 Django channel 的聊天:https://gearheart.io/blog/creating-a-chat-with-django-channels/

当我运行服务器时:$ python3 ./manage.py runserver redis 服务器没有启动。这是完整的消息:

 Performing system checks...

 System check identified no issues (0 silenced).
 April 27, 2017 - 20:59:01
 Django version 1.10.3, using settings 'multichat.settings'
 Starting Channels development server at http://127.0.0.1:8000/
 Channel layer default (asgi_redis.core.RedisChannelLayer)
 Quit the server with CONTROL-C.
 2017-04-27 20:59:01,278 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
 2017-04-27 20:59:01,279 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
 2017-04-27 20:59:01,282 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
 2017-04-27 20:59:01,282 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
 2017-04-27 20:59:01,283 - INFO - server - HTTP/2 support not enabled (install the http2 and tls Twisted extras)
 2017-04-27 20:59:01,283 - INFO - server - Using busy-loop synchronous mode on channel layer
 2017-04-27 20:59:01,284 - INFO - server - Listening on endpoint tcp:port=8000:interface=127.0.0.1
 2017-04-27 20:59:01,294 - ERROR - server - Error trying to receive messages: Error 61 connecting to localhost:6379. Connection refused.
 Exception in thread Thread-1:
 Traceback (most recent call last):
   File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 439, in connect
     sock = self._connect()
   File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 494, in _connect
     raise err
   File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 482, in _connect
     sock.connect(socket_address)
 ConnectionRefusedError: [Errno 61] Connection refused 

我可以通过从不同的终端运行 redis 服务器来解决它,但这正是 Django Channels 在设置中应该做的:

redis_host = os.environ.get('REDIS_HOST', 'localhost')
# Channel layer definitions
# http://channels.readthedocs.org/en/latest/deploying.html#setting-up-
a-channel-backend
CHANNEL_LAYERS = {
    "default": {
        # This example app uses the Redis channel layer implementation asgi_redis
    "BACKEND": "asgi_redis.RedisChannelLayer",
    "CONFIG": {
        "hosts": [(redis_host, 6379)],
    },
   "ROUTING": "multichat.routing.channel_routing", # We will create it in a moment
    },
}

感谢任何帮助和建议。

非常感谢!

最佳答案

参见 https://github.com/django/daphne#http2-support

你应该安装 Twisted pip install -U Twisted[tls,http2]

关于python - Django channel 不会使用 CHANNEL_LAYERS 启动 redis 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43668401/

相关文章:

python - 如何在 Python 中获取子类的泛型类型

python - 使用 XGboost 进行不平衡分类时如何使用下采样和配置类权重参数?

python - 如何将我的帖子创建者页面链接到 Python 中的其他页面?

mysql - SOLR 中的动态数据(如计数、观看次数等)- NRT 与 Redis?

java - jedis 交易成功响应

python - matplotlib生成动画,每个文件都是一个新帧

python - 删除两个等长数组中nan AND对应的元素

Django 模板 : How to show the time differences between a Datastore time and current time?

python - 如何使用 limit_choices_to 的上下文过滤 ModelAdmin autocomplete_fields 结果

mongodb - 一起使用 MongoDB 和 Redis?