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

107
Vistas
Redis sessions not persisting throughout different requests in express

I have 2 routes on the backend of my app. The first one sets a session using redis and using a different route i try to retrieve the session that was saved prior. However, when trying to retrieve the session, i get a different one from the one i created.

this is how i create a session and assign a property to it:

app.post("/login", (req, res) => {
req.session.userId = 1
});

and this is how i try to retrieve it:

app.get("/cookie", (req, res) => {
res.json(req.session);
});

But when the req.session of the get request is logged, I get one without the property userID. Even though, i am able to view the key and value of the session using the redis-client with the keys and mget command.

this is how the cookie and session is configured

app.use(
session({
  name: "cookie",
  store: new RedisStore({ client: redisClient }),
  secret: "xxxxx",
  resave: false,
  saveUninitialized: false,
  cookie: {
    secure: false,
    httpOnly: false,
    maxAge: 1000 * 60 * 10,
  },
})
);

and this is the redisClient:

const redisClient = redis.createClient({
host: "localhost",
port: 6379,
});

How do I properly retrieve the session that i set on the post request? Am I using redis entirely wrong or am i just missing something?

Thanks!

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