Skip to content

Commit

Permalink
fix: change check for cluster mode in clear
Browse files Browse the repository at this point in the history
  • Loading branch information
SaurusXI committed Jan 11, 2023
1 parent e85006e commit 3587d88
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}*`);
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3587d88

Please sign in to comment.