TypeScript: Why does my async Redis operation return undefined even though the command resolves successfully?

5 days ago 8
ARTICLE AD BOX

I’m working on a Node.js (v20) + TypeScript application using Redis Stack.
I’m trying to fetch data using an async function, but the return value is always undefined, even though the Redis command itself resolves successfully.

My function:

export async function getUserSession(sessionId: string) { try { const result = await redisClient.get(sessionId); console.log("Redis result:", result); // prints correct value return result; // returns undefined to caller } catch (err) { console.error(err); } }

How I call it:

const session = getUserSession("abc123"); console.log(session); // undefined

The function should return the actual Redis value as a resolved promise.

Actual behavior:

The returned value logs as undefined unless I manually add await inside the caller.

Read Entire Article