Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!