From 965df61ed2df298f27325f4d553e7d2de614f531 Mon Sep 17 00:00:00 2001 From: Nicolas Zelaya Date: Mon, 6 Nov 2023 14:39:32 -0300 Subject: [PATCH] RedisAdapter typing shadowed this --- src/storages/inRedis/RedisAdapter.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/storages/inRedis/RedisAdapter.ts b/src/storages/inRedis/RedisAdapter.ts index 423566f5..5a616c11 100644 --- a/src/storages/inRedis/RedisAdapter.ts +++ b/src/storages/inRedis/RedisAdapter.ts @@ -1,4 +1,4 @@ -import ioredis from 'ioredis'; +import ioredis, { Pipeline } from 'ioredis'; import { ILogger } from '../../logger/types'; import { merge, isString } from '../../utils/lang'; import { _Set, setToArray, ISet } from '../../utils/lang/sets'; @@ -89,12 +89,15 @@ export class RedisAdapter extends ioredis { }; const wrapCommand = (originalMethod: Function, methodName: string) => { + // The value of "this" in this function should be the instance actually executing the method. It might be the instance referred (the base one) + // or it can be the instance of a Pipeline object. return function () { const params = arguments; + const caller: (Pipeline | RedisAdapter) = this; // Need to change this crap to have TypeScript stop complaining const commandWrapper = () => { instance.log.debug(`${LOG_PREFIX} Executing ${methodName}.`); - const result = originalMethod.apply(this, params); + const result = originalMethod.apply(caller, params); if (thenable(result)) { // For handling pending commands on disconnect, add to the set and remove once finished.