api/store: implement has() method

This commit is contained in:
jj 2024-10-30 19:21:45 +00:00
parent 18acad19b9
commit 11314fb8d1
No known key found for this signature in database
3 changed files with 19 additions and 0 deletions

View file

@ -13,6 +13,15 @@ export class Store {
this.id = name;
}
async _has(_key) { throw "needs implementation" }
has(key) {
if (typeof key !== 'string') {
key = key.toString();
}
return this._has(key);
}
async _get(_key) { throw "needs implementation" }
async get(key) {
if (typeof key !== 'string') {

View file

@ -14,6 +14,10 @@ export default class MemoryStore extends Store {
super(name);
}
async _has(key) {
return this.#store.has(key);
}
async _get(key) {
const val = this.#store.get(key);

View file

@ -17,6 +17,12 @@ export default class RedisStore extends Store {
return this.id + '_' + key;
}
async _has(key) {
await this.#connected;
return this.#client.hExists(key);
}
async _get(key) {
await this.#connected;