我试图连接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
1条答案
按热度按时间uz75evzq1#
确保您不需要用户名和密码来连接到AWS ElastiCache上的Redis示例。如果需要,请在AWS客户端选项中提供用户名和密码选项。
const client = redis. sender Client({ host:'your-redis-cluster-name.xxxxxx.ng.0001.use1.cache.amazonaws.com',port:6379,});