Skip to content

Commit 4cf3f5b

Browse files
authored
Explicitly connect redis-client before providing to connect-redis (#359)
1 parent 0cb4086 commit 4cf3f5b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

@app/server/src/middleware/installSession.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ const MAXIMUM_SESSION_DURATION_IN_MILLISECONDS =
2323
parseInt(process.env.MAXIMUM_SESSION_DURATION_IN_MILLISECONDS || "", 10) ||
2424
3 * DAY;
2525

26-
export default (app: Express) => {
26+
async function createRedisStore() {
27+
const client = redis.createClient({
28+
url: process.env.REDIS_URL,
29+
});
30+
await client.connect();
31+
return new RedisStore({ client });
32+
}
33+
34+
export default async (app: Express) => {
2735
const rootPgPool = getRootPgPool(app);
2836

2937
const store = process.env.REDIS_URL
@@ -33,11 +41,7 @@ export default (app: Express) => {
3341
*
3442
* https://medium.com/mtholla/managing-node-js-express-sessions-with-redis-94cd099d6f2f
3543
*/
36-
new RedisStore({
37-
client: redis.createClient({
38-
url: process.env.REDIS_URL,
39-
}),
40-
})
44+
await createRedisStore()
4145
: /*
4246
* Using PostgreSQL for session storage is easy to set up, but increases
4347
* the load on your database. We recommend that you graduate to using

0 commit comments

Comments
 (0)