tj / connect-redis

Redis session store for Connect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instantiate under ES6/Module

BarryCarlyon opened this issue · comments

What would be the correct way to instantiate connect-redis via import ie as ES6/module.

I'm trying to do things the "new" way, and I've having fun getting ConnectRedis to instantiate.

This is something to also potentially add to the documentation

nothing special

import session from 'express-session'
import connectRedis from 'connect-redis'

const RedisStore = connectRedis(session)

Oh lawdy.

I think I tried that at one point and it hiccuped elsewhere.

Solved it:

import express from 'express';

import { createClient } from 'redis';
let redisClient = createClient({ legacyMode: true });
redisClient.connect().catch(console.error);

import session from 'express-session';
import connectRedis from 'connect-redis';
const RedisStore = connectRedis(session)

const serverSession = session({
    name: 'whatever',
    store: new RedisStore({
        client: redisClient
    }),
    secret: 'dfljkdsakljasdkljkasdlf',
    resave: true,
    saveUninitialized: true,
    cookie: {
        secure: true,
        httpOnly: false,
        domain: 'some.url.net'
    },
    rolling: true
})

Ta rubber ducks!