Correção para não instanciar o redis

pull/21/head
adriano 2023-01-06 07:08:40 -03:00
parent 37ab4b9564
commit 8059781c92
1 changed files with 37 additions and 33 deletions

View File

@ -7,12 +7,16 @@ import ListTicketServiceCache from "../services/TicketServices/ListTicketService
import { escapeCharCache } from './ContactsCache'
const redis = new Redis();
let redis: any = null
if (process.env.CACHE) {
redis = new Redis();
}
const redisConn = async () => {
if(!process.env.CACHE){
if (!process.env.CACHE) {
return null
}
@ -68,7 +72,7 @@ const flushCache = async () => {
const redis: any = await redisConn();
if(!redis) return false
if (!redis) return false
// if (redis.status === 'connect') {
@ -85,7 +89,7 @@ const cacheSize = async () => {
const redis: any = await redisConn();
if(!redis) return null
if (!redis) return null
// if (redis.status !== 'connect') return -1
@ -99,7 +103,7 @@ const loadTicketsCache = async () => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -135,7 +139,7 @@ const createTicketIndexCache = async (hashIndex: string) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -163,7 +167,7 @@ const updateTicketCache = async (hash: any, json_object: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -184,7 +188,7 @@ const updateTicketCacheByTicketId = async (ticketId: string | number, update_fie
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -218,7 +222,7 @@ const createOrUpdateTicketCache = async (hash: any, ticket: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -239,7 +243,7 @@ const deleteTicketsByIdCache = async (ticketId: string | number) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -267,7 +271,7 @@ const deleteTicketsFieldsCache = async (tickets: any, del_fields: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -299,7 +303,7 @@ const updateTicketsByContactsCache = async (oldNumber: string, newName: string,
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -336,7 +340,7 @@ const deleteTicketsByContactsCache = async (number: string) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -368,7 +372,7 @@ const deleteTicketCache = async (hash: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
@ -379,9 +383,9 @@ const deleteTicketCache = async (hash: any) => {
async function searchTicketCache(search: string, offset?: number, limit?: number) {
const redis:any = await redisConn();
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if(redis.status!=='connect') return null