Skip to content

Commit

Permalink
Merge pull request #6 from TiltingPoint/fix/redis-cluster/PLATFORM-2814
Browse files Browse the repository at this point in the history
Use correct type (`Redis.Cluster`) when connecting to Redis Cluster
  • Loading branch information
Evanjt1 authored Apr 30, 2024
2 parents c8eecfd + 9e4328c commit 856efa5
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
// store state of auth

import Redis from 'ioredis';
import Redis, {Cluster} from 'ioredis';
import { STATE_LIFETIME } from './constants';

let redis: Redis | undefined;
const redisConfig = {
host: process.env.REDIS_HOST,
port: +(process.env.REDIS_PORT || 6379),
options: {
username: process.env.REDIS_USERNAME,
password: process.env.REDIS_PASSWORD,
...(process.env.REDIS_ENABLE_TLS === 'true') && {tls: {
rejectUnauthorized: process.env.REDIS_CLUSTER !== 'true', // cert validation throwing error in cluster mode
}}
},
isCluster: process.env.REDIS_CLUSTER === 'true',
};

if (process.env.REDIS_URL) {
redis = new Redis(process.env.REDIS_URL);
let redis: Redis | Cluster | undefined;


if (process.env.REDIS_HOST) {
if (redisConfig.isCluster) {
redis = new Redis.Cluster([{host: redisConfig.host, port: redisConfig.port}], {redisOptions: redisConfig.options});
} else {
redis = new Redis({
host: redisConfig.host,
port: redisConfig.port,
...redisConfig.options
}
);
}
}

type State = {
Expand Down

0 comments on commit 856efa5

Please sign in to comment.