我正在尝试将 ElastiCache Redis 连接到部署在 ECS 上的 Express 服务器。我正在使用 Node.js 的官方 Redis 包
我从 ElastiCache 获得主端点作为
blablabla.mccjet.ng.0001.euc1.cache.amazonaws.com:6379
在我的服务器中,我尝试这样连接
const { createClient } = require("redis");
const pubClient = createClient({ url: 'blablabla.mccjet.ng.0001.euc1.cache.amazonaws.com:6379' });
但是当我查看 ECS 日志时,我看到了
/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:124
throw new TypeError('Invalid protocol');
^
TypeError: Invalid protocol
at Function.parseURL (/usr/src/app/node_modules/@redis/client/dist/lib/c...
没有使用过 Redis,所以不知道为什么会这样。知道如何正确使用端点
甚至尝试过
const pubClient = createClient({ host: 'blablabla.mccjet.ng.0001.euc1.cache.amazonaws.com', port:6379 });
但这也没有用
问题是我必须在我的
主要端点之前添加前缀
redis://
,这样它就变成了redis://blablabla.mccjet.ng.0001.euc1.cache.amazonaws.com:6379
const pubClient = createClient({ url: 'redis://blablabla.mccjet.ng.0001.euc1.cache.amazonaws.com:6379' });