gpt4 book ai didi

python - 如何在 gitlab 管道中从 Python 连接到 redis?

转载 作者:可可西里 更新时间:2023-11-01 11:23:25 25 4
gpt4 key购买 nike

按照以下说明进行操作:https://docs.gitlab.com/ce/ci/services/redis.html我已经添加了

services:
- redis:latest

到我的 .gitlab-ci.yml 文件,并更改为 redis 连接调用:

redis.StrictRedis(host='redis', port=6379, db=0)

我得到的错误是:

/usr/local/lib/python2.7/site-packages/redis/client.py:772: in execute_command
connection = pool.get_connection(command_name, **options)
/usr/local/lib/python2.7/site-packages/redis/connection.py:994: in get_connection
connection.connect()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = Connection<host=redis,port=6379,db=0>

def connect(self):
"Connects to the Redis server if not already connected"
if self._sock:
return
try:
sock = self._connect()
except socket.timeout:
raise TimeoutError("Timeout connecting to server")
except socket.error:
e = sys.exc_info()[1]
> raise ConnectionError(self._error_message(e))
E ConnectionError: Error -2 connecting to redis:6379. Name or service not known.

最佳答案

事实证明,这就像将服务声明放入每个任务一样简单,例如:

py27:
stage: run
image: python:2.7
script:
- mkdir -p build/coverage
- pip install -r requirements.txt
- pytest --color=no --verbose --ignore=almanac/migrations --cov=almanac --cov-config=.coveragerc tests
- cp .coverage build/coverage/py27.coverage
services: # <===== here ========
- redis:latest
artifacts:
paths:
- build/coverage/*.coverage

关于python - 如何在 gitlab 管道中从 Python 连接到 redis?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56756751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com