gpt4 book ai didi

node.js - 当来自 AWS ElastiCache Redis 的 'get' 时,nodejs 中的 ioredis 不执行任何操作

转载 作者:行者123 更新时间:2023-12-03 06:42:35 28 4
gpt4 key购买 nike

我在 ECS 上托管的 nodejs 容器中运行以下代码。这在本地使用 redis 运行良好。在 AWS 中,它似乎已连接(如果我使用无效地址,它会在连接时出错,所以我假设它已连接)。当我运行 redis.get( 时没有任何反应。我已经为 ioredis 启用了调试,当我尝试获取时收到 1 条消息:

2020-04-17T22:56:10.701Z ioredis:redis status[replica.virtual-happy-hour-redis.fnt3zc.usw2.cache.amazonaws.com:6379]: [empty] -> connecting
2020-04-17T22:56:11.042Z ioredis:redis status[10.200.0.37:6379]: connecting -> connect
2020-04-17T22:56:11.045Z ioredis:redis write command[10.200.0.37:6379]: 0 -> info([])
2020-04-17T23:02:02.627Z ioredis:redis queue command[10.200.0.37:6379]: 0 -> get([ 'friday' ])
# suspense is killing me....

这是代码

var Redis = require('ioredis'),

console.log('cache connecting to', CONFIG.CACHE_URL);
var redis = new Redis(CONFIG.CACHE_URL);
console.log('cache connected');

const getRoom = (roomName, callback) => {
let room;
console.log('getRoom', roomName); // this logs as expected, nothing after this does
try {
redis.get(roomName, (err, result) => {
if (err) {
console.log('get cache error', err);
} else {
if (result) {
console.log('cache result', result);
room = JSON.parse(result);
} else {
console.log('no cache', roomName);
room = defaultRoom(roomName);
redis.set(roomName, JSON.stringify(room));
}
}
if (callback) callback(room);
console.log('getRoom done');
});
} catch (ex) {
console.log('getRoom error', ex.toString());
}
};

我已确认安全组,ElastiCache 与我的 ECS 容器位于同一 VPC 中。我该怎么做才能解决此问题?

更新我用 redis 换掉了 ioredis 但它仍然发生,nada...

最佳答案

修复了!我不知道我(AWS 的新手)为传输中的加密配置了 ElastiCache。一旦我设置了身份验证 token 并将其与 ioredis 一起使用,它就可以工作了!我回来了!

关于node.js - 当来自 AWS ElastiCache Redis 的 'get' 时,nodejs 中的 ioredis 不执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61281397/

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