I’ve created a small function that uses the ioredis nodejs package to read from my Redis server. I am able to write to the cache but while reading I am not getting the result I want. The function is here:
static async getString(key: string): Promise<string> {
await redis.get(key, (err, result) => {
if (err) {
console.log(err)
return ''
}
else
return result
})
return 'q'
}
For some reason, the last return statement is being run (return ‘q’) before my redis.get function returns my result. Even if an error occurred, the last return statement should actually never execute right? I think I may be understanding something wrong about async await. The string with the key I am testing does exist though. When I return the result with a console.log(result), I am getting what I expect. But the function itself is returning ‘q’.

