3

当我尝试将我的 Nodsjs 应用程序连接到 Heroku 上的 RedisCloud 时,我收到以下错误

Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)

我什至尝试在代码中直接设置redis URL和端口来测试它。但是,它仍然尝试连接到 Heroku 上的 localhost,而不是 RedisCloud URL。

const {Queue} = require('bullmq');
const Redis = require('ioredis');

const conn = new Redis(
      'redis://rediscloud:mueSEJFadzE9eVcjFei44444RIkNO@redis-15725.c9.us-east-1-4.ec2.cloud.redislabs.com:15725'

// Redis Server Connection Configuration
console.log('\n==================================================\n');
console.log(conn.options, process.env.REDISCLOUD_URL);

const defaultQueue = () => {
    // Initialize queue instance, by passing the queue-name & redis connection
    const queue = new Queue('default', {conn});
    return queue;
};
module.exports = defaultQueue;

完整转储日志https://pastebin.com/N9awJYL9

4

1 回答 1

0

在 .env 文件上设置 REDISCLOUD_URL 如下

REDISCLOUD_URL =redis://rediscloud:password@hostname:port

从'ioredis'导入*作为Redis;export const redis = new Redis(process.env.REDISCLOUD_URL);

于 2021-05-10T17:52:06.830 回答