diff --git a/src/storages/inRedis/RedisAdapter.ts b/src/storages/inRedis/RedisAdapter.ts index 4a68ab49..c3d3ab8e 100644 --- a/src/storages/inRedis/RedisAdapter.ts +++ b/src/storages/inRedis/RedisAdapter.ts @@ -18,7 +18,7 @@ import { setToArray } from '../../utils/lang/sets'; const LOG_PREFIX = 'storage:redis-adapter: '; // If we ever decide to fully wrap every method, there's a Commander.getBuiltinCommands from ioredis. -const METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw']; +const METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'decr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw', 'hgetall', 'llen', 'hget']; const METHODS_TO_PROMISE_WRAP_EXEC = ['pipeline']; // Not part of the settings since it'll vary on each storage. We should be removing storage specific logic from elsewhere. @@ -45,7 +45,7 @@ interface IRedisCommand { /** * Redis adapter on top of the library of choice (written with ioredis) for some extra control. - * Refactored to use Composition and Proxy instead of Inheritance to support both v4 and v5. + * Refactored to use Composition instead of Inheritance to support both v4 and v5. */ export class RedisAdapter { // eslint-disable-next-line no-undef -- Index signature to allow proxying dynamic ioredis methods without TS errors @@ -73,23 +73,10 @@ export class RedisAdapter { this._listenToEvents(); this._setTimeoutWrappers(); this._setDisconnectWrapper(); + } - // Return a Proxy. This allows the adapter to act exactly like an extended class. - // If a method/property is accessed that we didn't explicitly wrap, it forwards it to `this.client`. - return new Proxy(this, { - get(target: RedisAdapter, prop: string | symbol) { - // If the property exists on our wrapper (like wrapped 'get', 'set', or internal methods) - if (prop in target) { - return target[prop as keyof RedisAdapter]; - } - // If it doesn't exist on our wrapper but exists on the real client (like 'on', 'quit') - if (target.client && prop in target.client) { - const val = target.client[prop]; - return typeof val === 'function' ? val.bind(target.client) : val; - } - return undefined; - } - }); + on(event: string, listener: (...args: any[]) => void) { + return this.client.on(event, listener); } _listenToEvents() { diff --git a/src/storages/inRedis/__tests__/ImpressionCountsCacheInRedis.spec.ts b/src/storages/inRedis/__tests__/ImpressionCountsCacheInRedis.spec.ts index 19e001b3..76a4e4b3 100644 --- a/src/storages/inRedis/__tests__/ImpressionCountsCacheInRedis.spec.ts +++ b/src/storages/inRedis/__tests__/ImpressionCountsCacheInRedis.spec.ts @@ -83,7 +83,7 @@ describe('IMPRESSION COUNTS CACHE IN REDIS', () => { test('POST IMPRESSION COUNTS IN REDIS FUNCTION', async () => { const connection = new RedisAdapter(loggerMock); // @TODO next line is not required with ioredis - await new Promise(res => connection.once('ready', res)); + await new Promise(res => connection.on('ready', res)); const counter = new ImpressionCountsCacheInRedis(loggerMock, key, connection); // Clean up in case there are still keys there. diff --git a/src/storages/inRedis/__tests__/UniqueKeysCacheInRedis.spec.ts b/src/storages/inRedis/__tests__/UniqueKeysCacheInRedis.spec.ts index 35f0aeb9..184131a3 100644 --- a/src/storages/inRedis/__tests__/UniqueKeysCacheInRedis.spec.ts +++ b/src/storages/inRedis/__tests__/UniqueKeysCacheInRedis.spec.ts @@ -147,7 +147,7 @@ describe('UNIQUE KEYS CACHE IN REDIS', () => { test('Should call "onFullQueueCb" when the queue is full. "popNRaw" should pop items.', async () => { const connection = new RedisAdapter(loggerMock); // @TODO next line is not required with ioredis - await new Promise(res => connection.once('ready', res)); + await new Promise(res => connection.on('ready', res)); const cache = new UniqueKeysCacheInRedis(loggerMock, key, connection, 3);