Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
How to connect nodejs redis client to redis cloud server?
const redis = require('redis');

const client = redis.createClient({
  host: 'redis-19606.redislabs.com',
  port: 19606,
  password: 'password'
});

client.on('ready', () => {
  console.log('redis is connected');
});

client.on('error', (err) => {
  console.log('redis is disconnected: ', err);
});

(async () => {
  try {
    await client.connect();
  } catch (error) {
    console.error('error while connecting redis', error);
  }
})();

This somehow does not seem to work. What am I doing wrong? It keeps connecting to 127.0.0.1:6379 which is the default config instead of what I am passing. This is only happening with nodejs client of redis. go-redis the golang client for redis is working flawlessly.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Just a guess, but which Node Redis version do you use? I had difficulties upgrading myself. The configuration of the client has changed since version 4.x.x. Since version 4.x.x you have to use a confiuration according to Client Configuration. Therefore use

const client = redis.createClient({
  socket: {
    host: 'redis-19606.redislabs.com',
    port: 19606,
  }
});

or use a URL

const client = redis.createClient({
  url: "redis://redis-19606.redislabs.com:19606"
});

Your client configuration matches the Node Redis version 3.x.x but not 4.x.x. Please see Redis NPM v3.1.2 and Redis NPM v4.0.1 for details.

about 4 years ago · Santiago Trujillo Relatório

0

you should maintain this format of Redis connecting string:

redis://:YOUR_PASSWORD@YOUR_ENDPOINT:YOUR_PORT
about 4 years ago · Santiago Trujillo Relatório

0

  1. What version of redis are you using?
  2. Do not explicitly conect to redis by writing "client.connect()" but instead use this after setting host, port and password:
    redisClient.on("connect", () => {})
    

and then you can use redisClient variable to get and set values.

  1. Also if you're trying to connect to a redislabs server then I think your host name might be incorrect and double check your host from redislabs.
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda