From 3587d888aefe389c0dd4be5eb24d1495d6cf2ece Mon Sep 17 00:00:00 2001 From: Shantanu Verma Date: Wed, 11 Jan 2023 12:01:10 +0530 Subject: [PATCH] fix: change check for cluster mode in clear --- lib/main.ts | 3 ++- tests/index.test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/main.ts b/lib/main.ts index ab802e6..e053c89 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -153,7 +153,8 @@ export class SugarCache { * This is an expensive operation (since it operates on all keys inside a namespace) and should be used with care */ public clear = async () => { - if (this.redis.isCluster) { + if (this.redis instanceof Cluster) { + console.log('here'); await Promise.all((this.redis as Cluster).nodes('master') .map(async (node) => { const deletionCandidateKeys = await node.keys(`${this.namespace}*`); diff --git a/tests/index.test.ts b/tests/index.test.ts index 68f3eaf..f9ec510 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -49,7 +49,7 @@ describe('Functional tests', () => { it('TTL based eviction', async () => { await cacheBasic.set(mockKey, mockVal, ttl); await new Promise((resolve) => { - setTimeout(resolve, ttl) + setTimeout(resolve, ttl * 1.1) }); const cachedVal = await cacheBasic.get(mockKey); expect(cachedVal).toBeNull();