MCPcopy
hub / github.com/chartbrew/chartbrew / setupRedisAdapter

Method setupRedisAdapter

server/modules/socketManager.js:102–179  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100 }
101
102 async setupRedisAdapter() {
103 try {
104 const redisConfig = getRedisOptions();
105
106 // Check if Redis is configured (host is set)
107 if (!redisConfig.host) {
108 console.log("Redis not configured, using in-memory adapter"); // eslint-disable-line
109 return;
110 }
111
112 // Create Redis clients for pub/sub with proper error handling
113 this.pubClient = new Redis({
114 ...redisConfig,
115 lazyConnect: true, // Don't connect immediately, we'll connect explicitly
116 maxRetriesPerRequest: null, // Required for adapter
117 enableReadyCheck: true,
118 retryStrategy(times) {
119 const delay = Math.min(times * 50, 2000);
120 return delay;
121 },
122 });
123
124 this.subClient = this.pubClient.duplicate();
125
126 // Set up error handlers before connecting
127 this.pubClient.on("error", (err) => {
128 console.error("Socket.IO Redis Pub Client Error:", err.message); // eslint-disable-line
129 });
130
131 this.subClient.on("error", (err) => {
132 console.error("Socket.IO Redis Sub Client Error:", err.message); // eslint-disable-line
133 });
134
135 // Set up reconnection handlers
136 this.pubClient.on("reconnecting", () => {
137 console.log("Socket.IO Redis Pub Client reconnecting..."); // eslint-disable-line
138 });
139
140 this.subClient.on("reconnecting", () => {
141 console.log("Socket.IO Redis Sub Client reconnecting..."); // eslint-disable-line
142 });
143
144 // Set up ready handlers
145 this.pubClient.on("ready", () => {
146 console.log("Socket.IO Redis Pub Client ready"); // eslint-disable-line
147 });
148
149 this.subClient.on("ready", () => {
150 console.log("Socket.IO Redis Sub Client ready"); // eslint-disable-line
151 });
152
153 // Connect both clients and wait for them to be ready
154 await Promise.all([
155 this.pubClient.connect(),
156 this.subClient.connect()
157 ]);
158
159 // Use Redis adapter for cross-process communication with recommended options

Callers 1

initializeMethod · 0.95

Calls 4

getRedisOptionsFunction · 0.85
onMethod · 0.80
connectMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected