Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
talha_silentcontent
/
src
/
queues
/
Filename :
redisClient.ts
back
Copy
// @ts-nocheck import IORedis from 'ioredis'; import {Queue, Worker} from 'bullmq' import longGenerate from '@/app/dbConfig/longGenerate'; // import * as redis from 'redis'; import {Redis} from 'ioredis'; const REDIS_USERNAME = process.env.REDIS_USERNAME; const REDIS_PASSWORD = process.env.REDIS_PASSWORD; const REDIS_HOST = process.env.REDIS_HOST; const REDIS_PORT = process.env.REDIS_PORT; // let redisClient; // let redisClientPromise; // if (process.env.NEXT_PUBLIC_NODE_ENV === 'development') { // if (!global._redisClientPromise) { // redisClient = redis.createClient({ // url: `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}` // }); // redisClient.connect().then(() => { // console.info( // `NextJS Redis client connected..` // ); // }).catch((error) => { // console.error(`[ERROR] Couldn't connect to Redis client: ${error}`); // }); // global._redisClientPromise = redisClient; // } // redisClientPromise = global._redisClientPromise // } else { // redisClient = redis.createClient({ // url: `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}` // }); // redisClient.connect().then(() => { // console.info( // `NextJS Redis client connected..` // ); // }).catch((error) => { // console.error(`[ERROR] Couldn't connect to Redis client: ${error}`); // }); // redisClientPromise = redisClient; // } // export default redisClientPromise; // const redisPort = parseInt(process.env.REDIS_PORT); // const redisHost = process.env.REDIS_HOST; // const redisPassword = process.env.REDIS_PASSWORD; // if (isNaN(redisPort) || !redisHost || !redisPassword) { // console.error('Invalid or missing Redis configuration in environment variables.'); // process.exit(1); // Exit the process with an error code // } // const connection = new IORedis({ // port: parseInt(REDIS_PORT), // host: REDIS_HOST, // password: REDIS_PASSWORD, // // maxRetriesPerRequest: null, // }); // connection.on("connect", () => { // console.log(`Connected to redis`); // }); // connection.on("error", (err) => { // console.log(`Error in Redis connection ${err}`); // }); // connection.on("end", () => { // console.log("Client disconnected from redis"); // }); // export default connection; // Ensure environment variables are read // const REDIS_PORT = process.env.REDIS_PORT; // const REDIS_HOST = process.env.REDIS_HOST; // const REDIS_PASSWORD = process.env.REDIS_PASSWORD; const globalForRedis = global as unknown as { redisClient: Redis }; const redisClient = globalForRedis.redisClient ?? new Redis({ port: parseInt(REDIS_PORT), host: REDIS_HOST, password: REDIS_PASSWORD, // host: '127.0.0.1', // port: 6379, }); // if (process.env.NODE_ENV !== 'production') { // globalForRedis.redisClient = redisClient; // } export default redisClient // // Initialize the Redis client in the global execution context to ensure uniqueness of the client // let client = global.redis; // let subscriber = global.redis; // // If no Redis client is found, create the client using detailed connection parameters // if (!client) { // client = global.redis = new IORedis({ // port: parseInt(REDIS_PORT), // default Redis port is 6379 // host: REDIS_HOST, // default Redis host is 'localhost' // password: REDIS_PASSWORD, // // Additional options can be set here. // }); // subscriber = global.redis = new IORedis({ // port: parseInt(REDIS_PORT), // default Redis port is 6379 // host: REDIS_HOST, // default Redis host is 'localhost' // password: REDIS_PASSWORD, // // Additional options can be set here. // }); // } // let connection; // const getRedisConnection = () => { // if (!connection) { // connection = new IORedis({ // port: parseInt(REDIS_PORT), // host: REDIS_HOST, // password: REDIS_PASSWORD, // }); // connection.on("connect", () => console.log(`Connected to redis`)); // connection.on("error", (err) => console.log(`Error in Redis connection: ${err}`)); // connection.on("end", () => console.log("Client disconnected from redis")); // } // return connection; // }; // const disconnectRedis = async () => { // if (connection) { // await connection.quit(); // connection = null; // Ensure reference is removed to allow reconnection // console.log("Disconnected from Redis"); // } // }; // export { getRedisConnection, disconnectRedis };