You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab CI流水线测试失败:Redis连接拒绝错误排查求助

Fixing Redis::CannotConnectError in GitLab CI Pipeline

Hey there, let's get that Redis connection issue sorted out! The problem here is how GitLab CI handles service containers—they don't run on the same localhost as your main job container, so pointing to 127.0.0.1 won't work.

What's Going Wrong?

In your .gitlab-ci.yml, you've added the redis:latest service, but your REDISTOGO_URL variable is still using localhost as the host. In GitLab CI, each service runs as a separate container, and you reference them by their service name (in this case, just redis) instead of localhost.

The Fix

Update your REDISTOGO_URL variable to use the service name as the host:

variables:
  MONGODB_URI: mongodb://mongo:27017/db_test
  REDISTOGO_URL: redis://redis:6379  # Changed localhost to redis

Extra Checks to Ensure It Works

  • Verify the service host is reachable: Add a quick test in your before_script to confirm Redis is up before running tests:
    - apt-get update && apt-get install -y redis-tools
    - redis-cli -h redis ping  # Should return "PONG" if connected
    
  • Check for hardcoded localhost in your app: Make sure your test environment config (like config/redis.yml or similar) isn't hardcoding 127.0.0.1—it should use the REDISTOGO_URL environment variable instead.

That should resolve the Errno::ECONNREFUSED error and let your tests connect to Redis successfully.

内容的提问来源于stack exchange,提问作者Tony Vincent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:15:43