Skip to content

Commit 84d1628

Browse files
authored
fix: redis connect failed (#292)
2 parents 55fdd6d + c91947b commit 84d1628

File tree

3 files changed

+80
-51
lines changed

3 files changed

+80
-51
lines changed

apps/backend/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"passport": "^0.6.0",
4949
"passport-jwt": "^4.0.1",
5050
"passport-oauth2": "^1.7.0",
51-
"redis": "^3.1.2",
51+
"redis": "^4.6.7",
5252
"reflect-metadata": "^0.1.13",
5353
"rxjs": "^7.8.1",
5454
"typeorm": "^0.3.17"
@@ -57,7 +57,6 @@
5757
"@nestjs/cli": "^10.0.3",
5858
"@nestjs/schematics": "^10.0.1",
5959
"@nestjs/testing": "^10.0.3",
60-
"@types/connect-redis": "^0.0.20",
6160
"@types/cookie-parser": "^1.4.3",
6261
"@types/csurf": "^1.11.2",
6362
"@types/express": "^4.17.17",

apps/backend/src/main.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
33
import { createClient } from 'redis';
4-
import * as connectRedis from 'connect-redis';
4+
import RedisStore from 'connect-redis';
55
import helmet from 'helmet';
66
import * as session from 'express-session';
77
import * as passport from 'passport';
@@ -33,11 +33,14 @@ async function bootstrap() {
3333
saveUninitialized: false,
3434
};
3535
if (process.env.NODE_ENV === 'production') {
36-
const redisClient = createClient({
37-
url: process.env.REDIS_URL,
38-
});
3936
try {
40-
const RedisStore = connectRedis(session);
37+
const redisClient = await createClient({
38+
url: process.env.REDIS_URL,
39+
});
40+
const redisStore = new RedisStore({
41+
client: redisClient,
42+
prefix: 'session:',
43+
});
4144
sessionOptions.store = new RedisStore({ client: redisClient });
4245
} catch (e) {
4346
Logger.error('Unable to connect to Redis');

pnpm-lock.yaml

+71-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)