Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda