I have a class named RedisManger in an typescript project. in that class I have a method to get info from redis database:
async Get(key: string): Promise<any> {
let value: any;
try {
this.client.get(key, async (err, data) => {
if (err) { value = err }
else {
value = data;
}
});
return value;
} catch (error) {
return error.message;
}
}
but it always returns undefined even though I can see my key has a value in redis-cli.
when I log data
in here :
this.client.get(key, async (err, data) => {
console.log(data)
});
It also prints undefined
how can I sovle my problem?
question from:
https://stackoverflow.com/questions/65867980/using-async-await-in-redis-on-nodejs 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…