Skip to content

Commit

Permalink
BC-6040 Upgrade Redis (#3411)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper authored Feb 20, 2024
1 parent 5c55860 commit a503d71
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 91 deletions.
11 changes: 9 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const compression = require('compression');
const redis = require('redis');
const connectRedis = require('connect-redis');
const RedisStore = require('connect-redis').default;
const session = require('express-session');
const methodOverride = require('method-override');
const csurf = require('csurf');
Expand Down Expand Up @@ -123,10 +123,17 @@ let sessionStore;
const redisUrl = REDIS_URI;
if (redisUrl) {
logger.info(`Using Redis session store at '${redisUrl}'.`);
const RedisStore = connectRedis(session);
const client = redis.createClient({
url: redisUrl,
});
client.connect().catch((err) => logger.error(err));

// The error event must be handled, otherwise the app crashes on redis connection errors.
// This is due to basic NodeJS behavior: https://nodejs.org/api/events.html#error-events
client.on('error', (err) => {
logger.error('Redis client error', err);
});

sessionStore = new RedisStore({ client });
} else {
logger.info('Using in-memory session store.');
Expand Down
251 changes: 164 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a503d71

Please sign in to comment.