node.js - 无法从谷歌云运行连接到 redis 公牛
问题描述
我正在尝试在 Google Cloud 运行上设置我的 redis 公牛。在本地一切正常。
服务器启动时我使用以下代码:
const client = redis.createClient('6379', '10.103.YYY.YYY');
这似乎奏效了。我在启动时没有收到任何错误。
当我尝试与 Bull 开展工作时,例如:
const actionQueue = new Bull(uuid(), {
redis: {
port: 6379, host: '10.103.YYY.YYY', tls: {
servername: '10.103.YYY.YYY'
}
}
});
await actionQueue.add();
actionQueue.process(async (job) => {
return this._job();
});
actionQueue.on('completed', async (job, actionId) => {
console.log(`Job completed with result ${actionId}`);
});
actionQueue.on("failed", (job, error) => {
console.log(job.id, error);
});
但是redis仍然连接到localhost ip&port。有人知道为什么这仍然连接到我的本地主机吗?我需要以不同的方式设置吗?
错误日志:
2020-11-21T14:55:35.794783Z <rejected> Error: connect ECONNREFUSED 127.0.0.1:6379
Standaard
2020-11-21T14:55:35.794791Z at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16) {
Standaard
2020-11-21T14:55:35.794798Z errno: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.794804Z code: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.794810Z syscall: 'connect',
Standaard
2020-11-21T14:55:35.794816Z address: '127.0.0.1',
Standaard
2020-11-21T14:55:35.794822Z port: 6379
Standaard
2020-11-21T14:55:35.794828Z }
Standaard
2020-11-21T14:55:35.794834Z}
Standaard
2020-11-21T14:55:35.794987Z The error was: Error: connect ECONNREFUSED 127.0.0.1:6379
Standaard
2020-11-21T14:55:35.794994Z at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16) {
Standaard
2020-11-21T14:55:35.795Z errno: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.795006Z code: 'ECONNREFUSED',
Standaard
2020-11-21T14:55:35.795011Z syscall: 'connect',
Standaard
2020-11-21T14:55:35.795017Z address: '127.0.0.1',
Standaard
2020-11-21T14:55:35.795022Z port: 6379
Standaard
2020-11-21T14:55:35.795028Z}
解决方案
Cloud Run 本身不与 VPC 对话。您需要在没有项目 VPC 的情况下连接无服务器世界。
为此,您必须使用无服务器 VPC 连接器。在部署 Cloud Run 的同一区域中创建。
然后将其附加到您的 Cloud Run 服务。像这样,私有范围(至少,您也可以路由所有传出流量)流量被路由到连接器并登陆您的 VPC。现在您可以访问您的 VPC 中的私有资源,例如您的 redis 实例。
推荐阅读
- python - 提供来自 django 的内容
- opencl - opencl:如何将 3d 纹理从主机传递到设备
- r - 使用 R 在闪亮的 App 中导入大文本图像
- javascript - RxJS:优雅的方式将源 Observable 划分为 3 个或更多 Observable
- javascript - 如何从 .filter() 返回布尔值
- qt - 我的自定义 QML 给出错误:“无法分配给不存在的属性”
- angular - 在 Angular 4 中导入 Google OAuth2Client
- haskell - 如何在 GHCi 中测试从标准输入读取的程序?
- sql - 如何标记最早的重叠记录?
- xpath - 如何使用 XPath 获取子值