简体   繁体   English

无法连接 django 上的 redis 哨兵

[英]cannot connect redis sentinels on django

I'm trying to connect sentinels, but every time we got the same error我正在尝试连接哨兵,但每次我们遇到相同的错误

Exception: Could not connect to any sentinel异常:无法连接到任何哨兵

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
               "hosts": [
                   { "sentinels": [("redis-cluster.local.svc.cluster.local", 26379, )]
                   , "master_name": "mymaster"}
                   ]}
        },
    }

I can't figure out where to put the password key and db key.我不知道把密码密钥和数据库密钥放在哪里。 And do I need to put in the url the sentinels url's?我是否需要输入 url 哨兵网址? or service is enough?还是服务就够了? note: when trying to connect redis/sentinels without channels we do not have any issue at all注意:当尝试在没有通道的情况下连接 redis/sentinels 时,我们根本没有任何问题

From the channels_redis readme :来自channels_redis自述文件

hosts主机

The server(s) to connect to, as either URIs, (host, port) tuples, or dicts conforming to create_connection.要连接到的服务器,作为 URI、(主机、端口)元组或符合 create_connection 的字典。 Defaults to ['localhost', 6379].默认为 ['localhost', 6379]。 Pass multiple hosts to enable sharding, but note that changing the host list will lose some sharded data.传递多个主机以启用分片,但要注意更改主机列表会丢失一些分片数据。

Sentinel connections require dicts conforming to create_sentinel with an additional master_name key specifying the Sentinel master set . Sentinel 连接需要符合create_sentinel的 dicts 以及指定 Sentinel master set 的附加 master_name 键 Plain Redis and Sentinel connections can be mixed and matched if sharding.如果分片,普通 Redis 和 Sentinel 连接可以混合匹配。

(emphasis mine) (强调我的)

From what I read it doesn't seem possible to use URIs for sentinel connections, so if you want to set the db and password keys you need to add the relevant keys in the hosts list item:根据我的阅读,似乎不可能将 URI 用于哨兵连接,因此如果您想设置数据库和密码密钥,您需要在hosts列表项中添加相关密钥:

CHANNEL_LAYERS = {
  "default": {
    "BACKEND": "channels_redis.core.RedisChannelLayer",
    "CONFIG": {
      "hosts": [
        {
          "sentinels": [
            ("redis-cluster.local.svc.cluster.local", 26379, )
          ],
          "master_name": "mymaster",
          "db": 0,
          "password": "your_password"
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM