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,14 +7,18 @@ 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
}
}
// try {
@ -66,9 +70,9 @@ const redisConn = async () => {
const flushCache = async () => {
const redis: any = await redisConn();
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,9 +103,9 @@ const loadTicketsCache = async () => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
await createTicketIndexCache('idx_ticket')
@ -135,9 +139,9 @@ const createTicketIndexCache = async (hashIndex: string) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
try {
@ -163,9 +167,9 @@ const updateTicketCache = async (hash: any, json_object: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
const pipeline = redis.pipeline()
let entries = Object.entries(json_object)
@ -184,9 +188,9 @@ const updateTicketCacheByTicketId = async (ticketId: string | number, update_fie
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
const ticket_cache = await redis.hgetall(`ticket:${ticketId}`)
@ -218,9 +222,9 @@ const createOrUpdateTicketCache = async (hash: any, ticket: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
ticket.escaped_name = escapeCharCache(ticket['contact.name'])
@ -239,9 +243,9 @@ const deleteTicketsByIdCache = async (ticketId: string | number) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
const ticket_cache = await redis.hgetall(`ticket:${ticketId}`)
@ -267,9 +271,9 @@ const deleteTicketsFieldsCache = async (tickets: any, del_fields: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
const pipeline = redis.pipeline()
@ -299,9 +303,9 @@ const updateTicketsByContactsCache = async (oldNumber: string, newName: string,
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
const pipeline = redis.pipeline()
@ -336,9 +340,9 @@ const deleteTicketsByContactsCache = async (number: string) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
const pipeline = redis.pipeline()
@ -368,9 +372,9 @@ const deleteTicketCache = async (hash: any) => {
const redis: any = await redisConn();
if(!redis) return
if (!redis) return
// if (redis.status !== 'connect') return
// if (redis.status !== 'connect') return
await redis.del(hash)
// await redis.quit()
@ -378,14 +382,14 @@ const deleteTicketCache = async (hash: any) => {
}
async function searchTicketCache(search: string, offset?: number, limit?: number) {
const redis:any = await redisConn();
if(!redis) return
const redis: any = await redisConn();
if (!redis) return
// if(redis.status!=='connect') return null
search = escapeCharCache(search)
search = escapeCharCache(search)
let response: any = undefined