The Life of a User Session

The Life of a User Session

Session Management is one of the many uses cases for Redis, but what do we really mean when we say Redis can be used as a session store? We’ll start with an overview of what sessions are in the context of web applications and cover some common use cases. Then we’ll look at the process of adding session management to a Node.js application using Redis as the session store. With basic session management in place, we’ll then explore options for situations where you may want to store session data after a session has ended.

Redis Day NYC 2019

49f894a7f36362469c7b69a993dc6453?s=128

Jan Kleinert

June 27, 2019
Tweet

Transcript

  1. PRESENTED BY

  2. PRESENTED BY

  3. PRESENTED BY

  4. PRESENTED BY 1 What are sessions? 2 Adding session management

    to a web app 3 What comes next? Agenda:
  5. PRESENTED BY What are sessions? Request Request Response Response

  6. PRESENTED BY Session ID Session Store Session ID and Session

    Data
  7. PRESENTED BY Let’s look at an example!

  8. PRESENTED BY express-session + connect-redis app.use(session({ genid: (req) => {

    return uuid() }, store: new redisStore({ host: 'localhost', port: 6379, client: redisClient }), name: '_redisDemo', secret: process.env.SESSION_SECRET, resave: false, cookie: { secure: false, maxAge: 60000 }, // Set to expire in 1 minute for demo purposes saveUninitialized: true }))
  9. PRESENTED BY But what about authentication?

  10. PRESENTED BY What did we add?

  11. PRESENTED BY

  12. PRESENTED BY You can use Redis as a cache and

    a session store! https://redislabs.com/blog/cache-vs-session-store/
  13. PRESENTED BY Example repo: https://github.com/jankleinert/redis-session-demo Modules used in these examples:

    • express-session: https://www.npmjs.com/package/express-session • connect-redis: https://www.npmjs.com/package/connect-redis • uuid: https://www.npmjs.com/package/uuid • passport: https://www.npmjs.com/package/passport Cache vs. Session Store blog: https://redislabs.com/blog/cache-vs-session-store/ Redis Enterprise Operator: https://github.com/RedisLabs/redis-enterprise-k8s-docs Try the operator mini-lab: http://bit.ly/2NgxBaK Find me on Twitter/Github: jankleinert Resources
  14. Thank you! Thank you!