django频道私人聊天

时间:2019-09-26 07:41:40

标签: python django django-channels

我正在使用Django频道创建Django私人聊天应用程序。我面临Redis的问题。有人告诉我Windows操作系统不支持Redis。有人可以替代吗?

settings.py Channel_layer

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("localhost", 6379)],
        },
    },
}

,显示的错误是

connected {'type': 'websocket.connect'}
WebSocket CONNECT /chat/abdullah/ [127.0.0.1:55869]
Exception inside application: ERR unknown command 'EVAL'
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels\sessions.py", line 183, in __call__
    return await self.inner(receive, self.send)
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels\middleware.py", line 41, in coroutine_call
    await inner_instance(receive, send)
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels\consumer.py", line 59, in __call__
    [receive, self.channel_receive], self.dispatch
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels\utils.py", line 59, in await_many_dispatch
    await task
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels\utils.py", line 51, in await_many_dispatch
    result = task.result()
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels_redis\core.py", line 429, in receive
    real_channel
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels_redis\core.py", line 484, in receive_single
    index, channel_key, timeout=self.brpop_timeout
  File "C:\Users\Unknown\PycharmProjects\online_forum\venv\lib\site-packages\channels_redis\core.py", line 327, in _brpop_with_clean
    await connection.eval(cleanup_script, keys=[], args=[channel, backup_queue])
  ERR unknown command 'EVAL'
WebSocket DISCONNECT /chat/abdullah/ [127.0.0.1:55869]

2 个答案:

答案 0 :(得分:0)

您可以从Windows下载ubuntu,而不是从ubuntu终端运行redis服务器-效果很好。

答案 1 :(得分:0)

您可以在 Windows 上使用 In Memory Channel 层进行开发。

虽然不鼓励在生产中使用。

CHANNEL_LAYERS = {
    'default': { 
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    },
}