Skip to content

Commit

Permalink
connect to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnardmoj committed Feb 6, 2025
1 parent 4ac805a commit d1bea9f
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const expressNunjucks = require('express-nunjucks').default
const session = require('express-session')
const RedisStore = require('connect-redis')(session)
const nunjucks = require('nunjucks')
const { createClient } = require('redis')
const IORedis = require('ioredis')
const { APP_PORT, REDIS_URL, REDIS_AUTH_TOKEN } = require('./config')

Expand All @@ -24,34 +23,18 @@ const sessionOptions = {
console.log('ENV:', app.get('env'))
console.log('REDIS:', REDIS_URL)

if (!!isDev) {
console.log('Connecting to Redis: ', 'master.cp-35a69c78e47785b1.iwfvzo.euw2.cache.amazonaws.com')
if (REDIS_URL) {
console.log('Connecting to Redis: ', REDIS_URL)

// Set up Redis (for sessions)
const redisClient = new IORedis({
host: process.env.REDIS_URL || 'redis',
// Settings for AWS Elasticache.
...(process.env.REDIS_AUTH_TOKEN && {
password: process.env.REDIS_AUTH_TOKEN,
...(REDIS_AUTH_TOKEN && {
password: REDIS_AUTH_TOKEN,
tls: {},
}),
})
// const redisClient = createClient({
// url: `rediss://${REDIS_URL}:6379`,
// password: REDIS_AUTH_TOKEN,
// // legacyMode: true,
// socket: {
// reconnectStrategy: (attempts) => {
// const nextDelay = Math.min(2 ** attempts * 20, 30000)
// console.log(`Retry Redis connection attempt: ${attempts}, next attempt in: ${nextDelay}ms`)
// return nextDelay
// },
// },
// })

redisClient.on('error', (err) => console.error('Redis Client Error', err));

redisClient.connect().catch(console.error)

sessionOptions.store = new RedisStore({ client: redisClient })
}
Expand Down

0 comments on commit d1bea9f

Please sign in to comment.