Skip to content

Inconsistency between clear and getKeys #336

@cjpearson

Description

@cjpearson

Environment

[email protected], node v20.9.0

Reproduction

Currently getKeys and clear behave differently when they are passed a prefix.

const prefix = 'test';
let keys = await storage.getKeys(prefix);
console.log(keys); // ['test:123', 'test:abc']
await storage.clear(prefix);
keys = await storage.getKeys(prefix);
console.log(keys); // ['test:123', 'test:abc']

clear seems to ignore the prefix if it is not a mount, while getKeys finds all keys which begin with the prefix. Since the options are named the same I had assumed they would behave similarly.

Describe the bug

Is this behavior intentional? Currently I'm working around it by individually deleting keys, but it would be nice if clear also worked.

const prefix = 'test';
let keys = await storage.getKeys(prefix);
console.log(keys); // ['test:123', 'test:abc']
await Promise.all(keys.map((k) => this.storage.removeItem(k)));
keys = await storage.getKeys(prefix);
console.log(keys); // []

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions