Skip to content

Commit

Permalink
Revert "Update index.ts with chatgpt redis error logging"
Browse files Browse the repository at this point in the history
This reverts commit d53f6b5.
  • Loading branch information
mikebenner committed Oct 23, 2024
1 parent d53f6b5 commit 489d07c
Showing 1 changed file with 1 addition and 38 deletions.
39 changes: 1 addition & 38 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,9 @@ const mqttUsername = "meshdev";
const mqttPassword = "large4cats";

const redisClient = createClient({
url: process.env.REDIS_URL, // Your Redis URL
socket: {
tls: true, // Enable TLS for secure connections
connectTimeout: 30000, // Set connection timeout (30 seconds)
keepAlive: 5000, // Send keep-alive packets every 5 seconds to prevent idle disconnects
},
// Retry strategy: handle connection failures with exponential backoff
retry_strategy: (options) => {
if (options.error && options.error.code === 'ECONNRESET') {
return new Error('Connection reset by the server');
}
if (options.total_retry_time > 1000 * 60 * 10) { // Stop after 10 minutes
return new Error('Retry time exhausted');
}
if (options.attempt > 10) { // Stop after 10 attempts
return undefined;
}
return Math.min(options.attempt * 100, 3000); // Exponential backoff
},
});

// Handle Redis client events to log connection issues
redisClient.on('error', (err) => {
console.error('Redis connection error: ', err);
url: process.env.REDIS_URL,
});

redisClient.on('ready', () => {
console.log('Redis connection established.');
});

redisClient.on('reconnecting', () => {
console.log('Reconnecting to Redis...');
});

// Connect the Redis client
redisClient.connect()
.then(() => console.log('Successfully connected to Redis'))
.catch((err) => console.error('Failed to connect to Redis: ', err));


(async () => {
if (process.env.REDIS_ENABLED === "true") {
// Connect to redis server
Expand Down

0 comments on commit 489d07c

Please sign in to comment.