Redis保持从AWS Elasticache断开和连接expressJS

e37o9pze  于 6个月前  发布在  Redis
关注(0)|答案(1)|浏览(84)

我试图连接redis在我的应用程序在expressJs,它是在localhost工作,但不是当我使用我的redisurl从AWS ElastiCache。
这是我的代码。Redis.js

const redis = require('redis');
require('dotenv').config();   

const client = redis.createClient( { url: process.env.REDIS_URL } ); 

client.on('connect', () => { console.log('Connected to Redis'); });  

(async () => { await client.connect(); })();  

client.on('error', (err) => { console.error("Redis Error: ${err}"); });  

client.on('reconnecting', () => console.log('client is reconnecting'));  

client.on('ready', () => console.log('client is ready'));

module.exports = client;

字符串
这是我的错误

Redis Error: Error: Connection timeout
client is reconnecting 
Redis Error: Error: Connection timeout 
client is reconnecting 
Redis Error: Error: Connection timeout client is reconnecting


一直都是这样。
我尝试使用host和url作为redis.createClient()的参数
Redis 4.6.x Node 18 Express 4.18.x

uz75evzq

uz75evzq1#

确保您不需要用户名和密码来连接到AWS ElastiCache上的Redis示例。如果需要,请在AWS客户端选项中提供用户名和密码选项。
const client = redis. sender Client({ host:'your-redis-cluster-name.xxxxxx.ng.0001.use1.cache.amazonaws.com',port:6379,});

相关问题