Redis无法在GitLab CI中连接

我从GitLab CI收到此错误。但是在本地开发人员上运行得很好。我尝试了几种方法来将Redis端口转换/解析为数字,还用console.log('Redis port type: ',typeof(REDIS_PORT)检查,返回number

这是CI的完整日志

$ npm run test:ci

> @apollo-knex/api@0.0.1 test:ci /builds/boilaplate/apollo-knex
> NODE_ENV=development jest --ci --coverage --detectOpenHandles --forceExit

{"level":50,"time":1573005891570,"pid":22,"hostname":"runner-ed2dce3a-project-14976649-concurrent-0","msg":"Redis client error: RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received NaN.","v":1}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @testpo/api@0.0.1 test:ci: `NODE_ENV=development jest --ci --coverage --detectOpenHandles --forceExit`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @apollo-knex/api@0.0.1 test:ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-11-06T02_04_51_595Z-debug.log
ERROR: Job failed: exit code 1

这是config.ts文件,用于获取环境变量。

// config.ts

export const {
  // ... bunch of others
  REDIS_PORT = 6379 
} = process.env

// Redis options for subscription pubsub,bull queue and ioredis
export const redisOptions = {
  host: REDIS_HOST,// Unary operator `+` to convert number
  port: +REDIS_PORT,// port: Number(REDIS_PORT),<- this does not work either
  password: REDIS_PASSWORD,}

我将ioredis用于Apollo GraphQL缓存和Bull队列。

// lib/redis.ts

// Tried adding redis connection options here,but didn't work
const redisClient = new Redis(redisOptions)

redisClient.on('connect',() => {
  logger.info('Redis client connected')
})

redisClient.on('error',err => {
  // I believe that the error is coming from here!
  logger.error(`Redis client error: ${err}`)
  process.exit(1)
})

export default redisClient

公牛队排队发送欢迎电子邮件

// auth/queue.ts

const emailQueue = {
  welcomeEmailQueue: new Queue('email',{ redis: redisOptions }),}

// ... other stuffs

请帮助我。我在做什么错了?

cmwapfang 回答:Redis无法在GitLab CI中连接

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3155334.html

大家都在问