mirror of
https://github.com/LukeHagar/pypistats.dev.git
synced 2025-12-07 04:21:11 +00:00
Enhance Redis client connection logic to skip connection if REDIS_URL is not set, with a warning message for clarity.
This commit is contained in:
@@ -6,10 +6,19 @@ let isConnecting = false;
|
|||||||
let isDisconnecting = false;
|
let isDisconnecting = false;
|
||||||
|
|
||||||
export function getRedisClient() {
|
export function getRedisClient() {
|
||||||
|
const redisUrl = process.env.REDIS_URL;
|
||||||
|
// Skip connecting if no REDIS_URL is provided (e.g., during build)
|
||||||
|
if (!redisUrl) {
|
||||||
|
if (typeof process !== 'undefined') {
|
||||||
|
console.warn('Redis disabled: REDIS_URL not set');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!redisClient && !isConnecting) {
|
if (!redisClient && !isConnecting) {
|
||||||
isConnecting = true;
|
isConnecting = true;
|
||||||
redisClient = createClient({
|
redisClient = createClient({
|
||||||
url: process.env.REDIS_URL || 'redis://localhost:6379',
|
url: redisUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
redisClient.on('error', (err) => {
|
redisClient.on('error', (err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user