Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda