Skip to content

Commit

Permalink
fixed namespace clear issue (#501)
Browse files Browse the repository at this point in the history
* fixed namespace clear issue

* fix test comments

* linting

* test cleanup

Co-authored-by: alphmth <>
  • Loading branch information
jaytist authored Sep 29, 2022
1 parent c877fb0 commit 0200279
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/redis/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class KeyvRedis extends EventEmitter {

clear() {
return this.redis.smembers(this._getNamespace())
.then(keys => this.redis.del([...keys, ...this._getNamespace()]))
.then(keys => this.redis.del([...keys, this._getNamespace()]))
.then(() => undefined);
}

Expand Down
29 changes: 29 additions & 0 deletions packages/redis/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,32 @@ test('close tls connection successfully', async t => {
t.pass();
}
});

test('.clear cleaned namespace', async t => {
// Setup
const keyv = new Keyv(redisURI, {
adapter: 'redis',
namespace: 'v3',
});

const length = 1;
const key = [...Array.from({length}).keys()].join('');

await keyv.set(key, 'value', 1);

await new Promise(r => {
setTimeout(r, 250);
});

await keyv.clear();
await keyv.disconnect();

// Test
const redis = new Redis(redisURI);

// Namespace should also expire after calling clear
t.true(await redis.exists('namespace:v3') === 0);

// Memory of each key should be null
t.true(await redis.memory('USAGE', 'namespace:v3') === null);
});

0 comments on commit 0200279

Please sign in to comment.