Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Can't get the data that stored in Redis

I'm trying to create a user after he verified the code that I send him so first I generate the code in sendCode resolver and save it in Redis using setex

the problem is that code is set in Redis but when I try to use it in createUser resolver using get it returns null.

const sendCode: MutationResolvers["sendCode"] = async ({
  input: { phoneNumber, email },
}: {
  input: SendCodeInput;
}) => {
  const code = generate4digitNum();
  await redis.setex(phoneNumber ?? email, THREE_MINS, code);
      return {};
    };



const createUser: MutationResolvers["createUser"] = async ({
  input: { ...userData },
}: {
  input: CreateUserInput;
}) => {
  
  const code = await redis.get(userData.phoneNumber ?? userData.email);
  if (code !== userData.code) {
    throw new Error(errors[0].id);
  }


  user = await userModel.create({ ...userData});

  return {type: user.type, _id: user._id };
};

the redis.ts file that I create:

const client = redis.createClient({
  host: process.env.REDIS_HOST,
  password: process.env.REDIS_PASSWORD,
  port: Number(process.env.REDIS_PORT),
});

client
  .on("connect", function () {
    console.log(`connected ${client.connected}`);
  })
  .on("error", function (error) {
    console.log(error);
  });

export const get: (key: string) => Promise<string> = promisify(client.get).bind(
  client
);

export const setex: (
  key: string,
  seconds: number,
  value: string
) => Promise<string> = promisify(client.setex).bind(client);

I will appreciate any kind of help. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!