【问题标题】:Connect to Redis hosted on GCP as VM instance连接到作为 VM 实例托管在 GCP 上的 Redis
【发布时间】:2018-06-13 06:59:12
【问题描述】:

我有一个作为 VM 托管在 Google 云平台上的 Redis 实例,它有一个 IP 地址、端口和密码。

我正在尝试从一个 dockerized python3 应用程序连接到这个实例。

我在 requirements.txt 文件中有redis 客户端库。

我要连接的代码是:

import redis
pool = redis.ConnectionPool(
                   host='redis://xxx.xxx.xxx.xxx',
                   port=6379,`
                   password=PASSWD
                   db=0
        )
cache = redis.Redis(connection_pool=pool)

当我尝试使用 cache 变量来减少值时,我收到以下异常:

redis.exceptions.ConnectionError: Error -2 connecting to redis://xxx.xxx.xxx.xxx:6379. Name does not resolve. 

感谢您的帮助。

【问题讨论】:

    标签: python-3.x docker redis gcp


    【解决方案1】:

    我通过从主机 arg 中删除 redis:// 并保持 IP 地址如下来运行它:

    pool = redis.ConnectionPool(
                   host='xxx.xxx.xxx.xxx',
                   port=6379,`
                   password=PASSWD
                   db=0
        )
    

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 2020-04-02
      • 2020-04-27
      • 2021-10-11
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多