fix(redis): add error handling and support no-auth Redis
This commit is contained in:
@@ -7,16 +7,30 @@ import { Queue, Worker, type QueueOptions } from 'bullmq';
|
||||
import IORedis from 'ioredis';
|
||||
|
||||
// Redis connection
|
||||
// Supports REDIS_URL (with or without password) or separate host/port
|
||||
const connection = process.env.REDIS_URL
|
||||
? new IORedis(process.env.REDIS_URL, {
|
||||
maxRetriesPerRequest: null,
|
||||
enableOfflineQueue: false,
|
||||
lazyConnect: true,
|
||||
})
|
||||
: new IORedis({
|
||||
host: process.env.REDIS_HOST || 'localhost',
|
||||
host: process.env.REDIS_HOST || 'redis',
|
||||
port: parseInt(process.env.REDIS_PORT || '6379'),
|
||||
maxRetriesPerRequest: null,
|
||||
enableOfflineQueue: false,
|
||||
lazyConnect: true,
|
||||
});
|
||||
|
||||
// Handle connection errors gracefully
|
||||
connection.on('error', (err) => {
|
||||
console.error('[Redis] Connection error:', err.message);
|
||||
});
|
||||
|
||||
connection.on('ready', () => {
|
||||
console.log('[Redis] Connected successfully');
|
||||
});
|
||||
|
||||
// Queue options
|
||||
const queueOptions: QueueOptions = {
|
||||
connection,
|
||||
|
||||
Reference in New Issue
Block a user