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

165
Views
trying to use express and redis to make a login web page

I'm trying to make a simple login page.I have to do it for university project.The problem is pretty simple, i'm trying to use redis to be the database for the users and passwords. The problem is that i can't extract the values out of the response that i get from redis.I got a docker running the redis image and every thing connect.In the example below im trying to make a simple boolean change from true to false according to the data inside the key (im using "a" as the key) but no matter what i do the value doesn't seem to change, it is note worthy that im very new to this and to js in particular, i read in the redis api that all of the funtions are asyncs i tried changing the code but it didnt help.

 app.get('/enter', (req, res) => {
  var username =req.query.user;
  var password = req.query.pass;
  ans = false
  redis.get(username,function(err, reply) {
    if(reply != null ) ans = true;
  })
  console.log(ans);
})

I just trying to verify that the key has a value, i tried to make a variable before and after the request but it isn't adjusting thanks for your time

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I see you dont understand the very very basics of callbacks and asynchronouse behaviour of javascript.

Well you can code like this:

app.get('/enter', async (req, res) => {
  var username =req.query.user;
  var password = req.query.pass;
  ans = false
  let reply = await getUsername(username)
  console.log(reply)
  console.log(ans);
})

function getUsername(username) {
   return new Promise((res, rej) => {
      redis.get(username, function(err, reply) {
         if(err) rej(err)
         res(reply)
      })
   })
}

You can just promisfy your redis code with new Promise and then you can use async / await style on it

Otherwise you need to write your code in the callback witch leads to an callback hell if you have more code

about 4 years ago · Juan Pablo Isaza Report
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!