If the given url is not proper or not valid or not able to connect, just let me move, don't hold me there, how can achive this?
I don't want the error to be occuring recursively causing halt of all the other process, ideally I guess I need to stop the event handler, How do i do that?
return is not working.
import dotenv from 'dotenv';
import { createClient } from 'redis';
dotenv.config();
let redis;
if (process.env.REDIS_URL) {
try {
redis = await createClient({
url: process.env.REDIS_URL,
disableOfflineQueue: true,
commandsQueueMaxLength: 1,
})
.on('error', (err) => {
console.log('Redis Client Error', err);
return null;
})
.connect();
console.log('Redis Connected');
} catch (error) {
console.error('Error connecting to Redis:', error.message);
redis = null;
}
} else {
console.log('Redis not configured, cache disabled.');
}
export { redis };