Adição do wait para fechar as conexões com o redis
parent
2c6b6c7309
commit
fc7d51a04f
|
@ -31,7 +31,7 @@ const deleteContactsByIdCache = async (id: string | number) => {
|
|||
console.log(`There was an error on deleteContactsByIdCache: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const updateContactCache = async (hash: any, json_object: any) => {
|
||||
|
@ -52,7 +52,7 @@ const updateContactCache = async (hash: any, json_object: any) => {
|
|||
|
||||
await pipeline.exec(() => { console.log("Key/value inserted/updated") });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ const updateContactCacheById = async (id: string | number, update_fields: object
|
|||
console.log(`There was an error on updateContactCacheById: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
||||
|
@ -99,7 +99,7 @@ const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
|||
|
||||
await redis.hmset(hash, contact);
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ async function searchContactCache(search: string, offset: number, limit: number)
|
|||
search = escapeCharCache(search)
|
||||
|
||||
const response: any = await redis.call('FT.SEARCH', 'idx_contact', `(@escaped_name:*${search}*)|(@number:*${search}*)`, 'LIMIT', offset, limit, 'SORTBY', 'escaped_name', 'ASC')
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
|
||||
if (response.length === 1) {
|
||||
|
@ -181,7 +181,7 @@ const insertContactsCache = async (contacts: any) => {
|
|||
|
||||
await pipeline.exec(() => { console.log(`${contacts.length} CONTACTS INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const loadContactsCache = async () => {
|
||||
|
@ -210,7 +210,7 @@ const loadContactsCache = async () => {
|
|||
|
||||
await pipeline.exec(() => { console.log(`${contacts.length} CONTACTS INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const createContactIndexCache = async (hashIndex: string) => {
|
||||
|
@ -238,7 +238,7 @@ const createContactIndexCache = async (hashIndex: string) => {
|
|||
console.log('There was an error on createContactIndexCache: ', error)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
@ -31,7 +31,7 @@ const deleteContactsByIdCache = async (id: string | number) => {
|
|||
console.log(`There was an error on deleteContactsByIdCache: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const updateContactCache = async (hash: any, json_object: any) => {
|
||||
|
@ -52,7 +52,7 @@ const updateContactCache = async (hash: any, json_object: any) => {
|
|||
|
||||
await pipeline.exec(() => { console.log("Key/value inserted/updated") });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ const updateContactCacheById = async (id: string | number, update_fields: object
|
|||
console.log(`There was an error on updateContactCacheById: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
||||
|
@ -101,7 +101,7 @@ const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
|||
|
||||
await redis.hmset(hash, contact);
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ async function searchContactCache(search: string, offset: number, limit: number)
|
|||
search = escapeCharCache(search)
|
||||
|
||||
const response: any = await redis.call('FT.SEARCH', 'idx_contact_message', `(@escaped_name:*${search}*)|(@number:*${search}*)`, 'LIMIT', offset, limit, 'SORTBY', 'escaped_name', 'ASC')
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
|
||||
if (response.length === 1) {
|
||||
|
@ -188,7 +188,7 @@ const insertMessageContactCache = async (hash: any, contact_message: any) => {
|
|||
|
||||
console.log('CREATED/UPDATED CONTACT MESSAGE')
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ const loadContactsCache = async () => {
|
|||
|
||||
await pipeline.exec(() => { console.log(`${contacts.length} CONTACTS INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const createContactMessageIndexCache = async (hashIndex: string) => {
|
||||
|
@ -246,7 +246,7 @@ const createContactMessageIndexCache = async (hashIndex: string) => {
|
|||
console.log('There was an error on contact_message: ', error)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
@ -38,7 +38,7 @@ const deleteScheduleByTicketIdCache = async (ticketId: string | number) => {
|
|||
console.log(`There was an error on deleteScheduleByTicketIdCache: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ const updateScheduleCacheByTicketId = async (scheduleNotify: any) => {
|
|||
|
||||
await pipeline.exec(() => { console.log("schedule Key/value inserted/updated") });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ const createSchedulingNotifyCache = async (scheduleNotify: any) => {
|
|||
|
||||
console.log(`${scheduleNotify.length} SCHEDULE NOTIFY INSERTED IN CACHE!`)
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ async function searchScheduleCache(date: string, hour: number | string, minute:
|
|||
date = escapeCharCache(date).trim()
|
||||
|
||||
const response: any = await redis.call('FT.SEARCH', 'idx_schedule', `(@date_escaped:${date}) (@hour:${hour}) (@minute:${minute})`)
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
|
||||
if (response.length === 1) {
|
||||
|
@ -173,7 +173,7 @@ const loadSchedulesCache = async () => {
|
|||
|
||||
await pipeline.exec(() => { console.log(`${schedules.length} SCHEDULES NOTIFY INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
|
||||
// let test = await searchScheduleCache('2022-12-16', '18', '30')
|
||||
|
@ -207,7 +207,7 @@ const createScheduleIndexCache = async (hashIndex: string) => {
|
|||
console.log('There was an error on createScheduleIndexCache: ', error)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
@ -20,11 +20,11 @@ const redisConn = async () => {
|
|||
|
||||
const conn = () => new Promise((resolve, reject) => {
|
||||
|
||||
redis.on('error', (err) => {
|
||||
redis.on('error', async (err) => {
|
||||
|
||||
if (err.code === 'ECONNREFUSED') {
|
||||
console.error(`Redis connection error: ${err}.`)
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
else {
|
||||
console.error(`Redis encountered an error: ${err.message}.`)
|
||||
|
@ -61,7 +61,7 @@ const flushCache = async () => {
|
|||
|
||||
console.log('TICKETS CACHE REMOVED')
|
||||
await redis.call('FLUSHALL')
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ const cacheSize = async () => {
|
|||
}
|
||||
|
||||
const size = await redis.call('dbsize')
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
return size
|
||||
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ const loadTicketsCache = async () => {
|
|||
|
||||
await pipeline.exec(() => { console.log(`${tickets.length} TICKETS INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,7 +143,7 @@ const createTicketIndexCache = async (hashIndex: string) => {
|
|||
console.log('There was an error on createTicketIndexCache: ', error)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const updateTicketCache = async (hash: any, json_object: any) => {
|
||||
|
@ -163,7 +163,7 @@ const updateTicketCache = async (hash: any, json_object: any) => {
|
|||
|
||||
await pipeline.exec(() => { console.log("updateTicketCache Key/value inserted/updated") });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ const updateTicketCacheByTicketId = async (ticketId: string | number, update_fie
|
|||
console.log(`There was an error on updateTicketCacheByTicketId: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ const createOrUpdateTicketCache = async (hash: any, ticket: any) => {
|
|||
|
||||
console.log('CREATED/UPDATED TICKET CACHE')
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ const deleteTicketsByIdCache = async (ticketId: string | number) => {
|
|||
console.log(`There was an error on deleteTicketsByIdCache: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ const deleteTicketsFieldsCache = async (tickets: any, del_fields: any) => {
|
|||
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -314,7 +314,7 @@ const updateTicketsByContactsCache = async (oldNumber: string, newName: string,
|
|||
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ const deleteTicketsByContactsCache = async (number: string) => {
|
|||
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ const deleteTicketCache = async (hash: any) => {
|
|||
if (redis.status !== 'connect') return
|
||||
|
||||
await redis.del(hash)
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -382,7 +382,7 @@ async function searchTicketCache(search: string, offset?: number, limit?: number
|
|||
else {
|
||||
response = await redis.call('FT.SEARCH', 'idx_ticket', `(@escaped_name:*${search}*)|(@contact_number:*${search}*)`)
|
||||
}
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
// console.log('response: ', response)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ const deleteWhatsappCache = async (hash:any) => {
|
|||
console.log(`There was an error on deleteWhatsappCache: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const updateWhatsappCache = async (hash: any, json_object: any) => {
|
||||
|
@ -53,7 +53,7 @@ const updateWhatsappCache = async (hash: any, json_object: any) => {
|
|||
|
||||
await pipeline.exec(() => { console.log("whatsapp Key/value inserted/updated") });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ const updateWhatsappCacheById = async (hash:any, update_fields: object | any) =>
|
|||
console.log(`There was an error on updateWhatsappCacheById: ${error}`)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
// const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
||||
|
@ -128,7 +128,7 @@ async function searchWhatsappCache(id: string, status: string) {
|
|||
const response: any = await redis.call('FT.SEARCH', 'idx_whatsapp', `(@status:*${status}*) (@number:*${number_cache.number}*)`, 'SORTBY', 'status', 'ASC')
|
||||
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
|
||||
|
||||
if (response.length === 1) {
|
||||
|
@ -183,7 +183,7 @@ const insertOrUpeateWhatsCache = async (hash:any, whatsapp: any) => {
|
|||
}
|
||||
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,7 +215,7 @@ const loadWhatsappCache = async () => {
|
|||
|
||||
await pipeline.exec(() => { console.log(`${whatsapps.length} WHATSAPPS INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
const createWhatsappIndexCache = async (hashIndex: string) => {
|
||||
|
@ -243,7 +243,7 @@ const createWhatsappIndexCache = async (hashIndex: string) => {
|
|||
console.log('There was an error on createWhatsappIndexCache: ', error)
|
||||
}
|
||||
|
||||
redis.quit()
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
Loading…
Reference in New Issue