将 Google Cloud Memorystore 与 App Engine 服务连接
Connecting Google Cloud Memorystore with App Engine service
我目前正在尝试将我的 App Engine node.js 服务连接到 Google Cloud Memorystore。
在这个 guide 之后,我需要在同一网络和区域(在我的例子中是欧洲)中都 运行。这似乎是不可能的,因为我只能在 europe-west-1 或 europe-west-4 中创建 Redis 实例,而 App Engine 为我提供 europe-west、europe-west-2 或 europe-west-3.
我假设 'same region' 代表 europe-west-x ?如果这是真的,我仍然无法连接,按照 gcloud 控制台(对于我的活动 Redis 实例)中的描述在 IP X.X.X.X:XXXX
上配置 Node.js 应用程序抛出连接失败,ETIMEDOUT
.
是地区原因吗?
该实例已将授权网络设置为 default
,并且应用程序 app.yaml 具有:
network:
name: default
更新:
即使我按照建议在 europe-west-1 中使用 GAE 并在 europe-west 中使用 Memorystor,我也会得到
Redis connection to X.X.X.X:XXXX failed - connect ETIMEDOUT
X.X.X.X:XXXX
我使用 node_redis 和以下代码片段来测试连接(REDIS_PORT 和 REDIS_IP 是我在 Memorystore 实例页面上看到的值):
const redis = require('redis');
let redisClient = redis.createClient(REDIS_PORT, REDIS_IP);
redisClient.set("string key", "string val", redis.print);
redisClient.hset("hash key", "hashtest 1", "some value", redis.print);
redisClient.hset(["hash key", "hashtest 2", "some other value"], redis.print);
redisClient.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
redisClient.quit();
});
redisClient.on("error", function (err) {
console.log("Redis rror " + err);
});
区域是特定的地理位置,每个区域有不同的区域(或只有一个)。例如,europe-west1-b 和 europe-west1-c 是相同的区域 (europe-west1) 但不同的区域 (b 或 c)。
此外,europe-west1 和 europe-west2 是不同的区域,方式相同 europe-west1 和 us-central1 是。
关于您的问题,europe-west 与 europe-west1 相同,所以你应该选择它来将 GAE 连接到 Memorystore。如果您选择两个不同的区域"numbers",因为它们是不同的区域,您将无法连接。
这是一段解释“Regions and zones”的文档:
- Regions are collections of zones. Zones have high-bandwidth, low-latency network connections to other zones in the same region. [...]
- A zone is an isolated location within a region. The fully-qualified name for a zone is made up of
region
-zone
. [...]
我意识到 GAE 服务必须 运行 在 flex 环境中,所以该应用程序也基于 Google Compute Engine。 env: flex
在 app.yaml 中丢失了。 GAE 和 Memorystore 之间的通信正在使用此配置。
我目前正在尝试将我的 App Engine node.js 服务连接到 Google Cloud Memorystore。 在这个 guide 之后,我需要在同一网络和区域(在我的例子中是欧洲)中都 运行。这似乎是不可能的,因为我只能在 europe-west-1 或 europe-west-4 中创建 Redis 实例,而 App Engine 为我提供 europe-west、europe-west-2 或 europe-west-3.
我假设 'same region' 代表 europe-west-x ?如果这是真的,我仍然无法连接,按照 gcloud 控制台(对于我的活动 Redis 实例)中的描述在 IP X.X.X.X:XXXX
上配置 Node.js 应用程序抛出连接失败,ETIMEDOUT
.
是地区原因吗?
该实例已将授权网络设置为 default
,并且应用程序 app.yaml 具有:
network:
name: default
更新:
即使我按照建议在 europe-west-1 中使用 GAE 并在 europe-west 中使用 Memorystor,我也会得到
Redis connection to X.X.X.X:XXXX failed - connect ETIMEDOUT X.X.X.X:XXXX
我使用 node_redis 和以下代码片段来测试连接(REDIS_PORT 和 REDIS_IP 是我在 Memorystore 实例页面上看到的值):
const redis = require('redis');
let redisClient = redis.createClient(REDIS_PORT, REDIS_IP);
redisClient.set("string key", "string val", redis.print);
redisClient.hset("hash key", "hashtest 1", "some value", redis.print);
redisClient.hset(["hash key", "hashtest 2", "some other value"], redis.print);
redisClient.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
redisClient.quit();
});
redisClient.on("error", function (err) {
console.log("Redis rror " + err);
});
区域是特定的地理位置,每个区域有不同的区域(或只有一个)。例如,europe-west1-b 和 europe-west1-c 是相同的区域 (europe-west1) 但不同的区域 (b 或 c)。
此外,europe-west1 和 europe-west2 是不同的区域,方式相同 europe-west1 和 us-central1 是。
关于您的问题,europe-west 与 europe-west1 相同,所以你应该选择它来将 GAE 连接到 Memorystore。如果您选择两个不同的区域"numbers",因为它们是不同的区域,您将无法连接。
这是一段解释“Regions and zones”的文档:
- Regions are collections of zones. Zones have high-bandwidth, low-latency network connections to other zones in the same region. [...]
- A zone is an isolated location within a region. The fully-qualified name for a zone is made up of
region
-zone
. [...]
我意识到 GAE 服务必须 运行 在 flex 环境中,所以该应用程序也基于 Google Compute Engine。 env: flex
在 app.yaml 中丢失了。 GAE 和 Memorystore 之间的通信正在使用此配置。