skip to Main Content

I am storing field in redis setex to see if field is already present for an email which is being sent to the function.

2

Answers


  1. This looks incorrect – you are only ever storing the single job-id and overwriting previous ones.

        if(listJobApps){
            jobArr = listJobApps.jobdids;
             let duplicate = jobArr.filter(job => job==jsnMessage.jobdid);
    
             if(duplicate.length > 0){
                return false;
             }
             else{
                jobArr.push(`${jsnMessage.jobdid}`);
                await onclickCache.setex(jsnMessage.email,JSON.stringify({jobdids:[`${jsnMessage.jobdid}`]}));
             }
        }
    

    It should be

    await onclickCache.setex(jsnMessage.email,JSON.stringify({jobdids:[`${jobArr}`]}));
    
    Login or Signup to reply.
  2. Looks like you’re looking for setnx, not setex. I’d put each email’s jobs in a hash of their own. (This is assuming you’re using a promiseful Redis library such as ioredis.)

    async function checkForDuplicate(message) {
      const email = message.email.toLowerCase();
      const jobdid = message.jobdid.toLowerCase();
      const res = await redis.hsetnx(`jobs:${email}`, jobdid, +new Date());
      if (res === 0) {
        // duplicate jobdid
        return null;
      }
      // jobdid was added to this email's jobs hash
      return jobdid;
    }
    
    async function getJobdids(message) {
      const email = message.email.toLowerCase();
      return redis.hkeys(`jobs:${email}`); // Promise of strings
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search