$30 off During Our Annual Pro Sale. View Details »

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

Jan Kleinert

June 27, 2019
Tweet

More Decks by Jan Kleinert

Other Decks in Technology

Transcript

  1. PRESENTED BY

    View Slide

  2. PRESENTED BY

    View Slide

  3. PRESENTED BY

    View Slide

  4. PRESENTED BY
    1 What are sessions?
    2 Adding session management to a web app
    3 What comes next?
    Agenda:

    View Slide

  5. PRESENTED BY
    What are sessions?
    Request
    Request
    Response
    Response

    View Slide

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

    View Slide

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

    View Slide

  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
    }))

    View Slide

  9. PRESENTED BY
    But what about authentication?

    View Slide

  10. PRESENTED BY
    What did we add?

    View Slide

  11. PRESENTED BY

    View Slide

  12. PRESENTED BY
    You can use Redis as a cache and a session store!
    https://redislabs.com/blog/cache-vs-session-store/

    View Slide

  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

    View Slide

  14. Thank you!
    Thank you!

    View Slide