var cachekey = null;
function redis_post(req, res, next) {
client.get(keyName, (err, redis_data) => {
if (err) {
throw err;
}
else if (!redis_data) {
client.set(keyName, JSON.stringify(key));
cachekey = JSON.parse(redis_data);
} else if (redis_data) {
cachekey = JSON.parse(redis_data);
}
// next()
})
// console.log("check"+cachekey) // undefined
}
const axiosInstance = axios.create({
baseURL: process.env.API_BASE_URL,
headers: {
'Content-type': 'application/json',
'accept': 'application/json',
'Authorization': cachekey // undefined
},
credentials: true
});
the problem was simple async await query, I just put async before redis_post func and await before client.get(key....)