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

111
Views
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
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!