title: How does redis persist Nodejs sessions?
body: <p>I recently started using Redis on my Nodejs project. I use it to store my sessions.</p>
  
  <pre><code>const session = require("express-session")
  const redis = require('redis')
  let RedisStore = require('connect-redis')(session)
  
  let redisClient
  if(process.env.REDISTOGO_URL){
      // let redisURL = url.parse(process.env.REDISTOGO_URL);
      redisClient = redis.createClient(process.env.REDISTOGO_URL)
  } else {
      redisClient = redis.createClient()
  }
  
  app.use(
          session({
              store: new RedisStore({
                  client: redisClient
              }),
              secret: keys.session.secret,
              resave: false,
              saveUninitialized: false
          })
      )
  </code></pre>
  
  <p>I am also using passport.js to handle user sessions:</p>
  
  <pre><code>passport.serializeUser(function(user, done) {
          done(null, user.id);
      });
  
      // used to deserialize the user
      passport.deserializeUser(function(id, done) {
          pool.query( `Select users.* where users.id = ${id} `, function(err, rows) {
              if(err){
                  console.log(err)
              }
              else{
                  done(err,rows[0]);    
              }
          });
      });
  </code></pre>
  
  <p>I was reading about how redis works and came upon this:</p>
  
  <blockquote>
    <p>When using a memory cache, your cookie only contains a session ID.
    This removes the risk of private user information being exposed in the
    cookie.</p>
  </blockquote>
  
  <p>This means that at any given time the Nodejs server still has to store the session ID. When the browser sends the cookie back with user infromation and the encrypted secret Nodejs will have to find the session ID in the redis store and make sure that the information is correct.</p>
  
  <p>Why is it that refreshing the Nodejs server not clear all the session ID from the database? Why do I not have to re-login everytime I refresh the server?</p>