microlinkhq/keyvhq

Feature Request: Add `.has` method

Kikobeats opened this issue · 5 comments

This is motivated to make the library more affordable to be adopted in user cases where you are already using Map or WeakMap.

In order to have a compatible API, keyv needs to add a . has method:

https://github.com/sindresorhus/mem/blob/main/index.ts#L63

I feel the addition of this new method will be done easily and the benefit could be huge.

In the worst scenario, it could be a sugar syntactic over .get:

const has = async (key) => await this.get(key) !== undefined

Although better if we can find a lightweight implementation per every store connector.

E.g., Redis can rely on EXISTS command so you don't need the value at all.

thoughts @Jytesh?

What should be the case if the user sets the value as undefined then?

We should also revalidate expiry keys in keyv

IMHO makes sense to consider undefined as an illegal value at .set since the undefined value is the value used by default when the value is not set.

If you really want to specify a nullish value, then use null

alright, makes sense