Каналы Django выдают ошибку при "async_to_sync(channel_layer.send)('test_channel', {'type':'hello'})".

Я пробую учебник по каналам django. Я дошел до той части, где мы убеждаемся, что канальный слой может взаимодействовать с redis. Я уже выполнил следующие команды-

$ docker run --rm -p 6379:6379 redis:7
$ python3 -m pip install channels_redis

# mysite/settings.py
# Channels
ASGI_APPLICATION = "mysite.asgi.application"
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("127.0.0.1", 6379)],
        },
    },
}

я должен запустить это->

$ python3 manage.py shell

>>>import channels.layers

>>>channel_layer = channels.layers.get_channel_layer()

>>>from asgiref.sync import async_to_sync

>>>async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})

>>>async_to_sync(channel_layer.receive)('test_channel')
{'type': 'hello'}`

но я продолжаю получать ошибку, что он не может соединиться с redis в строке ">>>async_to_sync(channel_layer.send)('test_channel', {'type':'hello'})"

ive run the tutorial commands but it keeps on showing error that it cannot connect to redis. there are so many lines of error. I asked gpt and it told that it cannot connect to redis

Вернуться на верх