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

199
Visualizações
can't get the data value in this callback function in node and redis

I have a node application that uses redis database to store my refresh tokens. I am trying to get the data value here in a callback function when I used the .get() method in redis. But it is not working. In postman, when I make request, it doesn't return anything. It stays on 'sending request' forever. Here is the function:

const {get, set} = require('../reditConnect');//coming from redis connection

 const refreshTokenverify = async (req, res, next) =>{

 try{
 const payload = jwt.verify(token, process.env.Refresh_Secret)
 req.user = {userId:payload.userId};
 console.log(req.user)
 
 await get(payload.userId.toString(), (err, data)=>{
    console.log(data)      
 });
 next()
 }catch(err){
 return res.status(401).json({message: "Invalid token"})
 
 }
 };

Here is redis connection code:

const redis = require('redis');
const { promisify } = require("util");
const redis_client = redis.createClient();
redis_client.connect()

redis_client.on('connect', function(){
console.log('redis client connected')
});


redis_client.on('ready', ()=>{
console.log("client is connected to redis and ready to use..")
});

redis_client.on('error', (err)=>{
console.log(err)
});

redis_client.on('end', ()=>{
console.log('client diconnected from redis')
});

process.on('SIGINT', ()=>{
redis_client.quit()
})

const get = promisify(redis_client.get).bind(redis_client);
 const set = promisify(redis_client.set).bind(redis_client)

 module.exports = {
 get,
 set
}

How do I approach this? The code stops working at console.log(req.user) I get a console.log for that but the request never ends, stays on sending request when I used postman.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

promisify will return promise so you dont need to use callback.

use this line

const data = await get(payload.userId.toString());

instead of this line

await get(payload.userId.toString(), (err, data)=>{
  console.log(data)      
});
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