From b579342b735f963dc773d22b0a99f8faf5653003 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Thu, 10 Oct 2024 02:10:26 -0400 Subject: [PATCH 01/21] Traduccion de Js a Ts de src/database/redis/list.js --- src/database/redis/list.ts | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/database/redis/list.ts diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts new file mode 100644 index 0000000000..f30bc49932 --- /dev/null +++ b/src/database/redis/list.ts @@ -0,0 +1,80 @@ +'use strict'; +import { createClient, RedisClientType } from 'redis'; +import * as helpers from './helpers'; + + +interface Module { + client: RedisClientType; + listPrepend(key: string, value: number | string): Promise; + listAppend(key: string, value: number | string): Promise; + listRemoveLast(key: string): Promise; + listRemoveAll(key: string, value: string[] | string): Promise; + listTrim(key: string, start: number, stop: number): Promise; + getListRange(key: string, start: number, stop: number): Promise; + listLength(key: string): Promise; +} + + +module.exports = function (module: Module) { + + + module.listPrepend = async function (key: string, value: any): Promise { + if (!key) { + return; + } + await module.client.lPush(key, value); + }; + + + module.listAppend = async function (key: string, value: any): Promise { + if (!key) { + return; + } + await module.client.rPush(key, value); + }; + + + module.listRemoveLast = async function (key: string): Promise { + if (!key) { + return null; + } + const result = await module.client.rPop(key); + return result || null; + }; + + + module.listRemoveAll = async function (key: string, value: string[] | string): Promise { + if (!key) { + return; + } + if (Array.isArray(value)) { + const batch = module.client.multi(); + value.forEach(value => batch.lRem(key, 0, value)); + await helpers.execBatch(batch); + } else { + await module.client.lRem(key, 0, value); + } + }; + + + module.listTrim = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return; + } + await module.client.lTrim(key, start, stop); + }; + + + module.getListRange = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return null; + } + const result = await module.client.lRange(key, start, stop); + return result || null; + }; + + + module.listLength = async function (key: string): Promise { + return await module.client.lLen(key); + }; +}; From 8b47ee222c15da9b290f8eb822dcdc06329ef43a Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Thu, 10 Oct 2024 21:58:48 -0400 Subject: [PATCH 02/21] Cambios en tipajes de la interface --- src/database/redis/list.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index f30bc49932..6165de62ff 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -2,11 +2,10 @@ import { createClient, RedisClientType } from 'redis'; import * as helpers from './helpers'; - interface Module { client: RedisClientType; - listPrepend(key: string, value: number | string): Promise; - listAppend(key: string, value: number | string): Promise; + listPrepend(key: string, value: any): Promise; + listAppend(key: string, value: any): Promise; listRemoveLast(key: string): Promise; listRemoveAll(key: string, value: string[] | string): Promise; listTrim(key: string, start: number, stop: number): Promise; @@ -14,7 +13,6 @@ interface Module { listLength(key: string): Promise; } - module.exports = function (module: Module) { From 986b47b7adab3c5bffce2cf139438aacb53970d1 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Thu, 10 Oct 2024 23:05:19 -0400 Subject: [PATCH 03/21] Agregadas lineas para deshabilitar eslint por tipaje de tipo any en list.ts + Agregado typeRoots en el tsconfig.json --- src/database/redis/list.ts | 129 +++++++++++++++++++------------------ tsconfig.json | 1 + 2 files changed, 66 insertions(+), 64 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 6165de62ff..697a80c279 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -1,6 +1,9 @@ -'use strict'; -import { createClient, RedisClientType } from 'redis'; -import * as helpers from './helpers'; +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ + +import { RedisClientType } from 'redis'; +import { execBatch } from './helpers'; interface Module { client: RedisClientType; @@ -14,65 +17,63 @@ interface Module { } module.exports = function (module: Module) { - - - module.listPrepend = async function (key: string, value: any): Promise { - if (!key) { - return; - } - await module.client.lPush(key, value); - }; - - - module.listAppend = async function (key: string, value: any): Promise { - if (!key) { - return; - } - await module.client.rPush(key, value); - }; - - - module.listRemoveLast = async function (key: string): Promise { - if (!key) { - return null; - } - const result = await module.client.rPop(key); - return result || null; - }; - - - module.listRemoveAll = async function (key: string, value: string[] | string): Promise { - if (!key) { - return; - } - if (Array.isArray(value)) { - const batch = module.client.multi(); - value.forEach(value => batch.lRem(key, 0, value)); - await helpers.execBatch(batch); - } else { - await module.client.lRem(key, 0, value); - } - }; - - - module.listTrim = async function (key: string, start: number, stop: number): Promise { - if (!key) { - return; - } - await module.client.lTrim(key, start, stop); - }; - - - module.getListRange = async function (key: string, start: number, stop: number): Promise { - if (!key) { - return null; - } - const result = await module.client.lRange(key, start, stop); - return result || null; - }; - - - module.listLength = async function (key: string): Promise { - return await module.client.lLen(key); - }; + module.listPrepend = async function (key: string, value: any): Promise { + if (!key) { + return; + } + await module.client.lPush(key, value); + }; + + + module.listAppend = async function (key: string, value: any): Promise { + if (!key) { + return; + } + await module.client.rPush(key, value); + }; + + + module.listRemoveLast = async function (key: string): Promise { + if (!key) { + return null; + } + const result = await module.client.rPop(key); + return result || null; + }; + + + module.listRemoveAll = async function (key: string, value: string[] | string): Promise { + if (!key) { + return; + } + if (Array.isArray(value)) { + const batch = module.client.multi(); + value.forEach(value => batch.lRem(key, 0, value)); + await execBatch(batch); + } else { + await module.client.lRem(key, 0, value); + } + }; + + + module.listTrim = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return; + } + await module.client.lTrim(key, start, stop); + }; + + + module.getListRange = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return null; + } + const result = await module.client.lRange(key, start, stop); + return result || null; + }; + + + module.listLength = async function (key: string): Promise { + return await module.client.lLen(key); + }; }; diff --git a/tsconfig.json b/tsconfig.json index 10aeeef7e6..7b08afd016 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "module": "commonjs", "moduleResolution": "node", "esModuleInterop": true, + "typeRoots": ["node_modules/@types"] }, "include": [ "public/src/**/*", From 3d0578acd87e68f9b48db1dbfd99321f51e73925 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Thu, 10 Oct 2024 23:21:26 -0400 Subject: [PATCH 04/21] Modificacion en importacion de redis --- src/database/redis/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 697a80c279..0c8793cf32 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import { RedisClientType } from 'redis'; +import type { RedisClientType } from 'redis'; import { execBatch } from './helpers'; interface Module { From 6bdfbb013303537e26cbc774a8f2f416ff474ab4 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Thu, 10 Oct 2024 23:46:15 -0400 Subject: [PATCH 05/21] Update redis package and add types for redis --- install/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install/package.json b/install/package.json index 183fc4a375..ac6c304775 100644 --- a/install/package.json +++ b/install/package.json @@ -121,6 +121,7 @@ "progress-webpack-plugin": "1.0.16", "prompt": "1.3.0", "ioredis": "5.4.1", + "redis": "^4.7.0", "rimraf": "5.0.7", "rss": "1.2.2", "rtlcss": "4.1.1", @@ -156,6 +157,7 @@ "@apidevtools/swagger-parser": "10.1.0", "@commitlint/cli": "19.3.0", "@commitlint/config-angular": "19.3.0", + "@types/redis": "^4.0.10", "@types/async": "^3.2.16", "@types/express": "^4.17.15", "@types/lodash": "^4.14.191", From bbd3165aa63d2a9b55e69315c6ba4c881c3ba333 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 00:12:12 -0400 Subject: [PATCH 06/21] =?UTF-8?q?Refactorizaci=C3=B3n=20de=20importaci?= =?UTF-8?q?=C3=B3n=20de=20redis=20y=20deshabilitaci=C3=B3n=20de=20eslint?= =?UTF-8?q?=20para=20ciertos=20casos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/redis/list.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 0c8793cf32..b089047c6a 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -1,12 +1,15 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-call */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ -import type { RedisClientType } from 'redis'; +// import type { RedisClientType } from 'redis'; import { execBatch } from './helpers'; interface Module { - client: RedisClientType; + client: any; listPrepend(key: string, value: any): Promise; listAppend(key: string, value: any): Promise; listRemoveLast(key: string): Promise; From 73a58cbfd8284004e0045941f3805a1dfe3e6f7a Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 00:19:05 -0400 Subject: [PATCH 07/21] Modificacion de mayusculas por minusculas en nombres de funciones de redis --- src/database/redis/list.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index b089047c6a..ea55a6abc1 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -24,7 +24,7 @@ module.exports = function (module: Module) { if (!key) { return; } - await module.client.lPush(key, value); + await module.client.lpush(key, value); }; @@ -32,7 +32,7 @@ module.exports = function (module: Module) { if (!key) { return; } - await module.client.rPush(key, value); + await module.client.rpush(key, value); }; @@ -40,7 +40,7 @@ module.exports = function (module: Module) { if (!key) { return null; } - const result = await module.client.rPop(key); + const result = await module.client.rpop(key); return result || null; }; @@ -63,7 +63,7 @@ module.exports = function (module: Module) { if (!key) { return; } - await module.client.lTrim(key, start, stop); + await module.client.ltrim(key, start, stop); }; @@ -71,12 +71,12 @@ module.exports = function (module: Module) { if (!key) { return null; } - const result = await module.client.lRange(key, start, stop); + const result = await module.client.lrange(key, start, stop); return result || null; }; module.listLength = async function (key: string): Promise { - return await module.client.lLen(key); + return await module.client.llen(key); }; }; From 9d72b08877e539420ed1f75aa1966283d0df3283 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 00:31:52 -0400 Subject: [PATCH 08/21] =?UTF-8?q?Refactorizar=20importaci=C3=B3n=20de=20Re?= =?UTF-8?q?dis=20y=20ajustar=20tipos=20en=20list.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/redis/list.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index ea55a6abc1..5cf23913b6 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -13,9 +13,9 @@ interface Module { listPrepend(key: string, value: any): Promise; listAppend(key: string, value: any): Promise; listRemoveLast(key: string): Promise; - listRemoveAll(key: string, value: string[] | string): Promise; + listRemoveAll(key: string, value: any): Promise; listTrim(key: string, start: number, stop: number): Promise; - getListRange(key: string, start: number, stop: number): Promise; + getListRange(key: string, start: number, stop: number): Promise; listLength(key: string): Promise; } From 44d53cf8f746e9b78fd5135b32353839710fb2e8 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 00:39:13 -0400 Subject: [PATCH 09/21] Correcion de tipajes en las definiciones de funciones de list.ts --- src/database/redis/list.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 5cf23913b6..8f6822c7d2 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -36,7 +36,7 @@ module.exports = function (module: Module) { }; - module.listRemoveLast = async function (key: string): Promise { + module.listRemoveLast = async function (key: string): Promise { if (!key) { return null; } @@ -67,7 +67,7 @@ module.exports = function (module: Module) { }; - module.getListRange = async function (key: string, start: number, stop: number): Promise { + module.getListRange = async function (key: string, start: number, stop: number): Promise { if (!key) { return null; } From ceda6c3b1a86fc3b4dd2fff591ffa71687009488 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 00:48:18 -0400 Subject: [PATCH 10/21] =?UTF-8?q?Refactorizar=20funci=C3=B3n=20de=20elimin?= =?UTF-8?q?aci=C3=B3n=20de=20elementos=20en=20lista=20Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/redis/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 8f6822c7d2..93911665de 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -50,7 +50,7 @@ module.exports = function (module: Module) { return; } if (Array.isArray(value)) { - const batch = module.client.multi(); + const batch = module.client.batch(); value.forEach(value => batch.lRem(key, 0, value)); await execBatch(batch); } else { From 12e9cd93a16c2391d0ee72e5e7b623478d3a22ff Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 01:04:05 -0400 Subject: [PATCH 11/21] Refactorizar tipos y funciones en list.ts de Redis --- src/database/redis/list.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 93911665de..2aac73e23d 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -12,7 +12,7 @@ interface Module { client: any; listPrepend(key: string, value: any): Promise; listAppend(key: string, value: any): Promise; - listRemoveLast(key: string): Promise; + listRemoveLast(key: string): Promise; listRemoveAll(key: string, value: any): Promise; listTrim(key: string, start: number, stop: number): Promise; getListRange(key: string, start: number, stop: number): Promise; @@ -45,7 +45,7 @@ module.exports = function (module: Module) { }; - module.listRemoveAll = async function (key: string, value: string[] | string): Promise { + module.listRemoveAll = async function (key: string, value: any): Promise { if (!key) { return; } From b73a34b93941ff78d8820165bf2e3e8d9a648919 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 01:32:22 -0400 Subject: [PATCH 12/21] Revertir cambios de retorno de algunas definiciones --- src/database/redis/list.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 2aac73e23d..3175340dd3 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -38,10 +38,10 @@ module.exports = function (module: Module) { module.listRemoveLast = async function (key: string): Promise { if (!key) { - return null; + return; } const result = await module.client.rpop(key); - return result || null; + return result; }; @@ -69,10 +69,10 @@ module.exports = function (module: Module) { module.getListRange = async function (key: string, start: number, stop: number): Promise { if (!key) { - return null; + return; } const result = await module.client.lrange(key, start, stop); - return result || null; + return result; }; From 7b67d20409155988980b3f0f5e0b7e4eeb2697bf Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Fri, 11 Oct 2024 01:54:12 -0400 Subject: [PATCH 13/21] =?UTF-8?q?Refactorizar=20puertos=20de=20Redis=20en?= =?UTF-8?q?=20archivo=20de=20configuraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yaml | 8 ++++---- install/package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c4e8f090bd..5a86904070 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,8 +30,8 @@ jobs: --health-timeout 5s --health-retries 5 ports: - # Maps port 6379 on service container to the host - - 6379:6379 + # Maps port 6380 on service container to the host + - 6380:6380 steps: - uses: actions/checkout@v4 @@ -61,7 +61,7 @@ jobs: "database": "redis", "redis:host": "127.0.0.1", - "redis:port": 6379, + "redis:port": 6380, "redis:password": "", "redis:database": 0 } @@ -69,7 +69,7 @@ jobs: { "host": "127.0.0.1", "database": 1, - "port": 6379 + "port": 6380 } run: | node app --setup="${SETUP}" --ci="${CI}" diff --git a/install/package.json b/install/package.json index ac6c304775..f572b491ad 100644 --- a/install/package.json +++ b/install/package.json @@ -158,7 +158,7 @@ "@commitlint/cli": "19.3.0", "@commitlint/config-angular": "19.3.0", "@types/redis": "^4.0.10", - "@types/async": "^3.2.16", + "@types/async": "^3.2.16", "@types/express": "^4.17.15", "@types/lodash": "^4.14.191", "@types/nconf": "^0.10.3", From 218c979ab39fadb9006573cf0310858aed4aa9d1 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 02:34:51 -0400 Subject: [PATCH 14/21] Correcciones en tipados e importaciones en src/database/redis/list.ts siendo cambios que localmente pasan el linter usando solo las excepciones permitidas: @typescript-eslint/no-unsafe-member-access y @typescript-eslint/no-unsafe-call --- src/database/redis/list.ts | 67 ++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 3175340dd3..58ccbc2009 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -1,82 +1,71 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ -// import type { RedisClientType } from 'redis'; +import { RedisClientType } from 'redis'; +import type { RedisCommandArgument as RedisCommandArg } from '@redis/client/dist/lib/commands'; import { execBatch } from './helpers'; -interface Module { - client: any; - listPrepend(key: string, value: any): Promise; - listAppend(key: string, value: any): Promise; - listRemoveLast(key: string): Promise; - listRemoveAll(key: string, value: any): Promise; - listTrim(key: string, start: number, stop: number): Promise; - getListRange(key: string, start: number, stop: number): Promise; - listLength(key: string): Promise; +interface RedisModule { + client: RedisClientType; + listPrepend?: (key: string, value: RedisCommandArg) => Promise; + listAppend?: (key: string, value: RedisCommandArg) => Promise; + listRemoveLast?: (key: string) => Promise; + listRemoveAll?: (key: string, value: RedisCommandArg | RedisCommandArg[]) => Promise; + listTrim?: (key: string, start: number, stop: number) => Promise; + getListRange?: (key: string, start: number, stop: number) => Promise; + listLength?: (key: string) => Promise; } -module.exports = function (module: Module) { - module.listPrepend = async function (key: string, value: any): Promise { +module.exports = function (module: RedisModule) { + module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { if (!key) { return; } - await module.client.lpush(key, value); + await module.client.lPush(key, value); }; - - module.listAppend = async function (key: string, value: any): Promise { + module.listAppend = async function (key: string, value: RedisCommandArg): Promise { if (!key) { return; } - await module.client.rpush(key, value); + await module.client.rPush(key, value); }; - - module.listRemoveLast = async function (key: string): Promise { + module.listRemoveLast = async function (key: string): Promise { if (!key) { - return; + return null; } - const result = await module.client.rpop(key); - return result; + return await module.client.rPop(key); }; - - module.listRemoveAll = async function (key: string, value: any): Promise { + module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { if (!key) { return; } if (Array.isArray(value)) { - const batch = module.client.batch(); - value.forEach(value => batch.lRem(key, 0, value)); + const batch = module.client.multi(); + value.forEach(val => batch.lRem(key, 0, val)); await execBatch(batch); } else { await module.client.lRem(key, 0, value); } }; - module.listTrim = async function (key: string, start: number, stop: number): Promise { if (!key) { return; } - await module.client.ltrim(key, start, stop); + await module.client.lTrim(key, start, stop); }; - - module.getListRange = async function (key: string, start: number, stop: number): Promise { + module.getListRange = async function (key: string, start: number, stop: number): Promise { if (!key) { - return; + return []; } - const result = await module.client.lrange(key, start, stop); - return result; + return await module.client.lRange(key, start, stop); }; - module.listLength = async function (key: string): Promise { - return await module.client.llen(key); + return await module.client.lLen(key); }; }; From d96f368ebca4113f263b56f82f6fc8dcb9bd9f72 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 02:41:42 -0400 Subject: [PATCH 15/21] Revertir cambio en el puerto usado para redis --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5a86904070..c4e8f090bd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,8 +30,8 @@ jobs: --health-timeout 5s --health-retries 5 ports: - # Maps port 6380 on service container to the host - - 6380:6380 + # Maps port 6379 on service container to the host + - 6379:6379 steps: - uses: actions/checkout@v4 @@ -61,7 +61,7 @@ jobs: "database": "redis", "redis:host": "127.0.0.1", - "redis:port": 6380, + "redis:port": 6379, "redis:password": "", "redis:database": 0 } @@ -69,7 +69,7 @@ jobs: { "host": "127.0.0.1", "database": 1, - "port": 6380 + "port": 6379 } run: | node app --setup="${SETUP}" --ci="${CI}" From 6f7f3ed3482469025cd392a4e94d8a00171cc9c0 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 02:47:21 -0400 Subject: [PATCH 16/21] Inicializacion del clienteRedis para evitar error TypeError: module.client.lPush is not a function durante la corrida de test --- src/database/redis/list.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 58ccbc2009..282e16df28 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import { RedisClientType } from 'redis'; +import { createClient, RedisClientType } from 'redis'; import type { RedisCommandArgument as RedisCommandArg } from '@redis/client/dist/lib/commands'; import { execBatch } from './helpers'; @@ -16,7 +16,17 @@ interface RedisModule { listLength?: (key: string) => Promise; } +const client: RedisClientType = createClient(); + +client.on('error', err => console.log('Redis Client Error', err)); + +(async () => { + await client.connect(); +})().catch(err => console.error('Error initializing Redis client:', err)); + module.exports = function (module: RedisModule) { + module.client = client; + module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { if (!key) { return; From 54d056ffa491c912d7e971a75186b52722f8edfb Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 03:01:32 -0400 Subject: [PATCH 17/21] Cambio de libreria "redis" por "ioredis" con consoles adicionales para visualizar si se esta realizando la conexion con redis adecuadamente --- src/database/redis/list.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 282e16df28..302e90dade 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import { createClient, RedisClientType } from 'redis'; +import Redis from 'ioredis'; import type { RedisCommandArgument as RedisCommandArg } from '@redis/client/dist/lib/commands'; import { execBatch } from './helpers'; interface RedisModule { - client: RedisClientType; + client: Redis; listPrepend?: (key: string, value: RedisCommandArg) => Promise; listAppend?: (key: string, value: RedisCommandArg) => Promise; listRemoveLast?: (key: string) => Promise; @@ -16,12 +16,14 @@ interface RedisModule { listLength?: (key: string) => Promise; } -const client: RedisClientType = createClient(); +const client = new Redis(); client.on('error', err => console.log('Redis Client Error', err)); (async () => { await client.connect(); + console.log('Redis client connected'); + console.log(client); })().catch(err => console.error('Error initializing Redis client:', err)); module.exports = function (module: RedisModule) { @@ -31,21 +33,21 @@ module.exports = function (module: RedisModule) { if (!key) { return; } - await module.client.lPush(key, value); + await module.client.lpush(key, value); }; module.listAppend = async function (key: string, value: RedisCommandArg): Promise { if (!key) { return; } - await module.client.rPush(key, value); + await module.client.rpush(key, value); }; module.listRemoveLast = async function (key: string): Promise { if (!key) { return null; } - return await module.client.rPop(key); + return await module.client.rpop(key); }; module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { @@ -53,11 +55,11 @@ module.exports = function (module: RedisModule) { return; } if (Array.isArray(value)) { - const batch = module.client.multi(); - value.forEach(val => batch.lRem(key, 0, val)); + const batch = module.client.pipeline(); + value.forEach(val => batch.lrem(key, 0, val)); await execBatch(batch); } else { - await module.client.lRem(key, 0, value); + await module.client.lrem(key, 0, value); } }; @@ -65,17 +67,17 @@ module.exports = function (module: RedisModule) { if (!key) { return; } - await module.client.lTrim(key, start, stop); + await module.client.ltrim(key, start, stop); }; module.getListRange = async function (key: string, start: number, stop: number): Promise { if (!key) { return []; } - return await module.client.lRange(key, start, stop); + return await module.client.lrange(key, start, stop); }; module.listLength = async function (key: string): Promise { - return await module.client.lLen(key); + return await module.client.llen(key); }; }; From dbdadd393a5a31e793cf765c1c5676cf46a15f41 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 03:14:27 -0400 Subject: [PATCH 18/21] Modificacion por inicializacion aparentemente innecesaria en list.ts que hace que entre los logs se generen: Error initializing Redis client: Error: Redis is already connecting/connected --- src/database/redis/list.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 302e90dade..ccae101924 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -18,14 +18,6 @@ interface RedisModule { const client = new Redis(); -client.on('error', err => console.log('Redis Client Error', err)); - -(async () => { - await client.connect(); - console.log('Redis client connected'); - console.log(client); -})().catch(err => console.error('Error initializing Redis client:', err)); - module.exports = function (module: RedisModule) { module.client = client; From 3b650f1d90b3a39a56d915b8247cc053c689dcaa Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 03:22:33 -0400 Subject: [PATCH 19/21] =?UTF-8?q?Refactorizaci=C3=B3n=20de=20list.ts=20par?= =?UTF-8?q?a=20mejorar=20la=20gesti=C3=B3n=20de=20errores=20y=20agregar=20?= =?UTF-8?q?mensajes=20de=20consola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/redis/list.ts | 126 +++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 46 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index ccae101924..91326c1c1f 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -19,57 +19,91 @@ interface RedisModule { const client = new Redis(); module.exports = function (module: RedisModule) { - module.client = client; + module.client = client; - module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { - if (!key) { - return; - } - await module.client.lpush(key, value); - }; + module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { + if (!key) { + return; + } + try { + await module.client.lpush(key, value); + } catch (err) { + console.error('Error in listPrepend:', err); + } + }; - module.listAppend = async function (key: string, value: RedisCommandArg): Promise { - if (!key) { - return; - } - await module.client.rpush(key, value); - }; + module.listAppend = async function (key: string, value: RedisCommandArg): Promise { + if (!key) { + return; + } + try { + await module.client.rpush(key, value); + } catch (err) { + console.error('Error in listAppend:', err); + } + }; - module.listRemoveLast = async function (key: string): Promise { - if (!key) { - return null; - } - return await module.client.rpop(key); - }; + module.listRemoveLast = async function (key: string): Promise { + if (!key) { + return null; + } + try { + return await module.client.rpop(key); + } catch (err) { + console.error('Error in listRemoveLast:', err); + return null; + } + }; - module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { - if (!key) { - return; - } - if (Array.isArray(value)) { - const batch = module.client.pipeline(); - value.forEach(val => batch.lrem(key, 0, val)); - await execBatch(batch); - } else { - await module.client.lrem(key, 0, value); - } - }; + module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { + if (!key) { + return; + } + try { + if (Array.isArray(value)) { + const batch = module.client.pipeline(); + value.forEach((val) => batch.lrem(key, 0, val)); + await execBatch(batch); + } else { + await module.client.lrem(key, 0, value); + } + } catch (err) { + console.error('Error in listRemoveAll:', err); + } + }; - module.listTrim = async function (key: string, start: number, stop: number): Promise { - if (!key) { - return; - } - await module.client.ltrim(key, start, stop); - }; + module.listTrim = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return; + } + try { + await module.client.ltrim(key, start, stop); + } catch (err) { + console.error('Error in listTrim:', err); + } + }; - module.getListRange = async function (key: string, start: number, stop: number): Promise { - if (!key) { - return []; - } - return await module.client.lrange(key, start, stop); - }; + module.getListRange = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return []; + } + try { + return await module.client.lrange(key, start, stop); + } catch (err) { + console.error('Error in getListRange:', err); + return []; + } + }; - module.listLength = async function (key: string): Promise { - return await module.client.llen(key); - }; + module.listLength = async function (key: string): Promise { + if (!key) { + return 0; + } + try { + return await module.client.llen(key); + } catch (err) { + console.error('Error in listLength:', err); + return 0; + } + }; }; From 03855d8cd0960bdfc74ca92f967abf2baa0f1104 Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 03:23:18 -0400 Subject: [PATCH 20/21] Correcciones a list.ts usando npx eslint --fix src/database/redis/list.ts --- src/database/redis/list.ts | 160 ++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index 91326c1c1f..f4fd34a964 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -19,91 +19,91 @@ interface RedisModule { const client = new Redis(); module.exports = function (module: RedisModule) { - module.client = client; + module.client = client; - module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { - if (!key) { - return; - } - try { - await module.client.lpush(key, value); - } catch (err) { - console.error('Error in listPrepend:', err); - } - }; + module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { + if (!key) { + return; + } + try { + await module.client.lpush(key, value); + } catch (err) { + console.error('Error in listPrepend:', err); + } + }; - module.listAppend = async function (key: string, value: RedisCommandArg): Promise { - if (!key) { - return; - } - try { - await module.client.rpush(key, value); - } catch (err) { - console.error('Error in listAppend:', err); - } - }; + module.listAppend = async function (key: string, value: RedisCommandArg): Promise { + if (!key) { + return; + } + try { + await module.client.rpush(key, value); + } catch (err) { + console.error('Error in listAppend:', err); + } + }; - module.listRemoveLast = async function (key: string): Promise { - if (!key) { - return null; - } - try { - return await module.client.rpop(key); - } catch (err) { - console.error('Error in listRemoveLast:', err); - return null; - } - }; + module.listRemoveLast = async function (key: string): Promise { + if (!key) { + return null; + } + try { + return await module.client.rpop(key); + } catch (err) { + console.error('Error in listRemoveLast:', err); + return null; + } + }; - module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { - if (!key) { - return; - } - try { - if (Array.isArray(value)) { - const batch = module.client.pipeline(); - value.forEach((val) => batch.lrem(key, 0, val)); - await execBatch(batch); - } else { - await module.client.lrem(key, 0, value); - } - } catch (err) { - console.error('Error in listRemoveAll:', err); - } - }; + module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { + if (!key) { + return; + } + try { + if (Array.isArray(value)) { + const batch = module.client.pipeline(); + value.forEach(val => batch.lrem(key, 0, val)); + await execBatch(batch); + } else { + await module.client.lrem(key, 0, value); + } + } catch (err) { + console.error('Error in listRemoveAll:', err); + } + }; - module.listTrim = async function (key: string, start: number, stop: number): Promise { - if (!key) { - return; - } - try { - await module.client.ltrim(key, start, stop); - } catch (err) { - console.error('Error in listTrim:', err); - } - }; + module.listTrim = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return; + } + try { + await module.client.ltrim(key, start, stop); + } catch (err) { + console.error('Error in listTrim:', err); + } + }; - module.getListRange = async function (key: string, start: number, stop: number): Promise { - if (!key) { - return []; - } - try { - return await module.client.lrange(key, start, stop); - } catch (err) { - console.error('Error in getListRange:', err); - return []; - } - }; + module.getListRange = async function (key: string, start: number, stop: number): Promise { + if (!key) { + return []; + } + try { + return await module.client.lrange(key, start, stop); + } catch (err) { + console.error('Error in getListRange:', err); + return []; + } + }; - module.listLength = async function (key: string): Promise { - if (!key) { - return 0; - } - try { - return await module.client.llen(key); - } catch (err) { - console.error('Error in listLength:', err); - return 0; - } - }; + module.listLength = async function (key: string): Promise { + if (!key) { + return 0; + } + try { + return await module.client.llen(key); + } catch (err) { + console.error('Error in listLength:', err); + return 0; + } + }; }; From 8d27b818a491d9011564c7c933fdd9a8642a336a Mon Sep 17 00:00:00 2001 From: AnyaMarcanito <19-10336@usb.ve> Date: Mon, 14 Oct 2024 16:30:24 -0400 Subject: [PATCH 21/21] Eliminacion de librerias de redis y definicion de interfaces para evitar problemas al compilar el proyecto + Archivo list.js compilado --- src/database/redis/list.js | 273 +++++++++++++++++++++++++++++-------- src/database/redis/list.ts | 45 +++--- 2 files changed, 246 insertions(+), 72 deletions(-) diff --git a/src/database/redis/list.js b/src/database/redis/list.js index 101ef178e3..8a83d24405 100644 --- a/src/database/redis/list.js +++ b/src/database/redis/list.js @@ -1,57 +1,220 @@ -'use strict'; - +"use strict"; +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); + return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var helpers_1 = require("./helpers"); module.exports = function (module) { - const helpers = require('./helpers'); - - module.listPrepend = async function (key, value) { - if (!key) { - return; - } - await module.client.lpush(key, value); - }; - - module.listAppend = async function (key, value) { - if (!key) { - return; - } - await module.client.rpush(key, value); - }; - - module.listRemoveLast = async function (key) { - if (!key) { - return; - } - return await module.client.rpop(key); - }; - - module.listRemoveAll = async function (key, value) { - if (!key) { - return; - } - if (Array.isArray(value)) { - const batch = module.client.batch(); - value.forEach(value => batch.lrem(key, 0, value)); - await helpers.execBatch(batch); - } else { - await module.client.lrem(key, 0, value); - } - }; - - module.listTrim = async function (key, start, stop) { - if (!key) { - return; - } - await module.client.ltrim(key, start, stop); - }; - - module.getListRange = async function (key, start, stop) { - if (!key) { - return; - } - return await module.client.lrange(key, start, stop); - }; - - module.listLength = async function (key) { - return await module.client.llen(key); - }; + module.listPrepend = function (key, value) { + return __awaiter(this, void 0, void 0, function () { + var err_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, module.client.lpush(key, value)]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + err_1 = _a.sent(); + console.error('Error in listPrepend:', err_1); + return [3 /*break*/, 4]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + module.listAppend = function (key, value) { + return __awaiter(this, void 0, void 0, function () { + var err_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, module.client.rpush(key, value)]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + err_2 = _a.sent(); + console.error('Error in listAppend:', err_2); + return [3 /*break*/, 4]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + module.listRemoveLast = function (key) { + return __awaiter(this, void 0, void 0, function () { + var err_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/, null]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, module.client.rpop(key)]; + case 2: return [2 /*return*/, _a.sent()]; + case 3: + err_3 = _a.sent(); + console.error('Error in listRemoveLast:', err_3); + return [2 /*return*/, null]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + module.listRemoveAll = function (key, value) { + return __awaiter(this, void 0, void 0, function () { + var batch_1, err_4; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 6, , 7]); + if (!Array.isArray(value)) return [3 /*break*/, 3]; + batch_1 = module.client.pipeline(); + value.forEach(function (val) { return batch_1.lrem(key, 0, val); }); + return [4 /*yield*/, (0, helpers_1.execBatch)(batch_1)]; + case 2: + _a.sent(); + return [3 /*break*/, 5]; + case 3: return [4 /*yield*/, module.client.lrem(key, 0, value)]; + case 4: + _a.sent(); + _a.label = 5; + case 5: return [3 /*break*/, 7]; + case 6: + err_4 = _a.sent(); + console.error('Error in listRemoveAll:', err_4); + return [3 /*break*/, 7]; + case 7: return [2 /*return*/]; + } + }); + }); + }; + module.listTrim = function (key, start, stop) { + return __awaiter(this, void 0, void 0, function () { + var err_5; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, module.client.ltrim(key, start, stop)]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + err_5 = _a.sent(); + console.error('Error in listTrim:', err_5); + return [3 /*break*/, 4]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + module.getListRange = function (key, start, stop) { + return __awaiter(this, void 0, void 0, function () { + var err_6; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/, []]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, module.client.lrange(key, start, stop)]; + case 2: return [2 /*return*/, _a.sent()]; + case 3: + err_6 = _a.sent(); + console.error('Error in getListRange:', err_6); + return [2 /*return*/, []]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + module.listLength = function (key) { + return __awaiter(this, void 0, void 0, function () { + var err_7; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!key) { + return [2 /*return*/, 0]; + } + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, module.client.llen(key)]; + case 2: return [2 /*return*/, _a.sent()]; + case 3: + err_7 = _a.sent(); + console.error('Error in listLength:', err_7); + return [2 /*return*/, 0]; + case 4: return [2 /*return*/]; + } + }); + }); + }; }; diff --git a/src/database/redis/list.ts b/src/database/redis/list.ts index f4fd34a964..5f0ab1e6f9 100644 --- a/src/database/redis/list.ts +++ b/src/database/redis/list.ts @@ -1,27 +1,38 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import Redis from 'ioredis'; -import type { RedisCommandArgument as RedisCommandArg } from '@redis/client/dist/lib/commands'; import { execBatch } from './helpers'; +interface batch { + lrem(key: string, count: number, value: string): batch; +} + +interface Redis { + lpush(key: string, value: string[] | string): Promise; + rpush(key: string, value: string[] | string): Promise; + rpop(key: string): Promise; + lrem(key: string, count: number, value: string): Promise; + ltrim(key: string, start: number, stop: number): Promise; + lrange(key: string, start: number, stop: number): Promise; + llen(key: string): Promise; + pipeline(): batch; + exec(): Promise; +} + interface RedisModule { client: Redis; - listPrepend?: (key: string, value: RedisCommandArg) => Promise; - listAppend?: (key: string, value: RedisCommandArg) => Promise; - listRemoveLast?: (key: string) => Promise; - listRemoveAll?: (key: string, value: RedisCommandArg | RedisCommandArg[]) => Promise; - listTrim?: (key: string, start: number, stop: number) => Promise; - getListRange?: (key: string, start: number, stop: number) => Promise; - listLength?: (key: string) => Promise; + listPrepend(key: string, value: string[] | string): Promise; + listAppend(key: string, value: string[] | string): Promise; + listRemoveLast(key: string): Promise; + listRemoveAll(key: string, value: string[] | string): Promise; + listTrim(key: string, start: number, stop: number): Promise; + getListRange(key: string, start: number, stop: number): Promise; + listLength(key: string): Promise; } -const client = new Redis(); module.exports = function (module: RedisModule) { - module.client = client; - - module.listPrepend = async function (key: string, value: RedisCommandArg): Promise { + module.listPrepend = async function (key: string, value: string[] | string): Promise { if (!key) { return; } @@ -32,7 +43,7 @@ module.exports = function (module: RedisModule) { } }; - module.listAppend = async function (key: string, value: RedisCommandArg): Promise { + module.listAppend = async function (key: string, value: string[] | string): Promise { if (!key) { return; } @@ -43,7 +54,7 @@ module.exports = function (module: RedisModule) { } }; - module.listRemoveLast = async function (key: string): Promise { + module.listRemoveLast = async function (key: string): Promise { if (!key) { return null; } @@ -55,7 +66,7 @@ module.exports = function (module: RedisModule) { } }; - module.listRemoveAll = async function (key: string, value: RedisCommandArg | RedisCommandArg[]): Promise { + module.listRemoveAll = async function (key: string, value: string[] | string): Promise { if (!key) { return; } @@ -83,7 +94,7 @@ module.exports = function (module: RedisModule) { } }; - module.getListRange = async function (key: string, start: number, stop: number): Promise { + module.getListRange = async function (key: string, start: number, stop: number): Promise { if (!key) { return []; }