django channels,docker compose,errno 111]连接调用失败('127.0.0.2',6379)

vs91vp4v  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(1150)

我正在关注django频道的教程https://channels.readthedocs.io/en/latest/tutorial/part_2.html
我正在使用docker compose构建redis服务器: docker-compose.yml ```
redis:
image: "redis:alpine"

  1. command: redis-server --requirepass letmein
  2. ports:
  3. - "6379:6379"
  4. volumes:
  5. - ./redis.conf:/usr/local/etc/redis/redis.conf
  6. environment:
  7. - REDIS_REPLICATION_MODE=master
  8. networks:
  9. node_net:
  10. ipv4_address: 127.0.0.2

networks:
node_net:
ipam:
driver: default
config:
- subnet: 127.0.0.0/16

  1. 尝试测试与的连接时

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

  1. 我得到了错误

File "<console>", line 1, in <module> File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 120, in __call__ return call_result.result() File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 425, in result return self.__get_result() File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result raise self._exception File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 180, in main_wrap result = await self.awaitable(*args,**kwargs) File "/usr/local/lib/python3.6/site-packages/channels_redis/core.py", line 299, in send async with self.connection(index) as connection: File "/usr/local/lib/python3.6/site-packages/channels_redis/core.py", line 835, in __aenter__ self.conn = await self.pool.pop() File "/usr/local/lib/python3.6/site-packages/channels_redis/core.py", line 73, in pop conns.append(await aioredis.create_redis(**self.host, loop=loop)) File "/usr/local/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 175, in create_redis loop=loop) File "/usr/local/lib/python3.6/site-packages/aioredis/connection.py", line 113, in create_connection timeout) File "/usr/local/lib/python3.6/asyncio/tasks.py", line 339, in wait_for return (yield from fut) File "/usr/local/lib/python3.6/site-packages/aioredis/stream.py", line 24, in open_connection lambda: protocol, host, port,**kwds) File "/usr/local/lib/python3.6/asyncio/base_events.py", line 794, in create_connection raise exceptions[0] File "/usr/local/lib/python3.6/asyncio/base_events.py", line 781, in create_connection yield from self.sock_connect(sock, address) File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 439, in sock_connect return (yield from fut) File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 469, in _sock_connect_cb raise OSError(err, 'Connect call failed %s' % (address,)) ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.2', 6379)

  1. docker[errno 111]connect call failed'127.0.0.1'6379)上提供的建议描述了更改 `127.0.0.1:6379` `redis:6379` . 但目前尚不清楚这种变化应发生在何处:
  2. 在我的 `settings.py` ?

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

  1. 或者在我的 `docker-compose.yml` ? 或者别的地方?提前感谢:)
kkih6yb8

kkih6yb81#

你有 '127.0.0.2' 而不是 '127.0.0.1' 对于本地主机

相关问题