Spaces:
Build error

PrimeStake Deployer
Fix Redis connection handling: add in-memory fallback for local dev and suppress error logs
07996b5
Raw History Blame Contribute Delete
1.02 kB
import { createClient } from 'redis';
const redisClient = createClient({
url: process.env.REDIS_URL || 'redis://localhost:6379',
socket: {
reconnectStrategy: (retries) => {
if (retries > 5) {
console.log('Redis reconnection stopped (Max retries). Client will remain disconnected.');
return false; // Stop retrying
}
return Math.min(retries * 100, 3000);
}
}
});
redisClient.on('error', (err) => {
if (err.code === 'ECONNREFUSED') {
// Suppress connection refused logs to avoid spam in development
} else {
console.error('Redis Client Error', err.message);
}
});
redisClient.on('connect', () => console.log('Redis Client Connected'));
(async () => {
if (process.env.NODE_ENV !== 'test') {
try {
await redisClient.connect();
} catch (err) {
console.error('Redis connection failed (non-fatal):', err.message);
// We don't exit process here to allow the server to start even if Redis fails
}
}
})();
export default redisClient;