redis / redis/node-redis

accessing cache inside a promise is not working ok

Open
#1,539 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
17.6k
Forks
2k
Avg merge
2d 3h
Merged PRs (30d)
40

Description

Issue

I am doing the following inside a function which is called as a promise:
let cachedData = await init(redisKey);
if(cachedData){
logger.info("FOUND CACHED MENUDATA...");
return cachedData;
} else {
logger.info("NOTFOUND CACHED MENUDATA...", venueId);
}

However the control always comes to the else and prints "NOT FOUND CACHED MENUDATA". After that it prints logs inside the redis.readCache function.

const init = async(redisKey) => {
const cachedData = await redis.readCache(redisKey);
console.log(Hi CACHED DATA GOT,cachedData);
return cachedData;
};


Environment
  • Node.js Version: 8
  • Redis Version: 3
  • Platform: ubuntu 20

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the reported call through init(redisKey), then inspect redis.readCache and the promise timing around its return. Done means a cache hit is returned from init before the fallback branch runs, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, redis
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.