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

119
Visualizações
No any output from hello world of node.js redis

I am learning the book Redis Essentials by Maxwell Dayvson Da Silva and Hugo Lopes Tavares. It tells redis in node.js. The node.js in this book is very old, i.e. v0.12.4. And my node.js on my Ubuntu 20.04 is v10.19.0. I am working in python now. But I am familiar with JS in browsers, and with the hope that I can go through it, I decided to try the node.js. Could you tell me why the below code has not any output when I can ping-pong in redis-cli. Like below:

$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> SET key001 value001
OK
127.0.0.1:6379> GET key001
"value001"
127.0.0.1:6379> QUIT

$ node hello.js
$

(I have fixed the problem between line 2 and line 3, i.e. explicit connection.)

(I feel the root cause may be my node.js version is too higher than that in the book. I guess the process exits before the printing is executed. But I am not familiar with current node.js. Please help me!)

//hello.js
var redis = require("redis"); // 1
var client = redis.createClient(); // 2
client.connect(); // Important: explict conn is needed now!
client.set("my_key", "Hello World using Node.js and Redis"); // 3
client.get("my_key", redis.print); // 4
client.quit(); // 5
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is because the implementation of the redis client in nodejs is using Asyc/Await approach.

So, you may need to do something like the below instead.

(async () => {
  const client = createClient();

  client.on('error', (err) => console.log('Redis Client Error', err));

  await client.connect();

  await client.set('key', 'value');
  const value = await client.get('key');
  await client.quit();
})();

Ref: https://github.com/redis/node-redis

about 4 years ago · Juan Pablo Isaza 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