23 lines
497 B
JavaScript
23 lines
497 B
JavaScript
import { createClient } from 'redis';
|
|
|
|
const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';
|
|
|
|
export async function createRedisClient() {
|
|
try {
|
|
const client = createClient({
|
|
url: REDIS_URL
|
|
});
|
|
|
|
await client.connect();
|
|
console.log('Connected to Redis');
|
|
|
|
client.on('error', (err) => {
|
|
console.error('Redis error:', err);
|
|
});
|
|
|
|
return client;
|
|
} catch (error) {
|
|
console.error('Redis connection error:', error);
|
|
throw error;
|
|
}
|
|
}
|