mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
api/store: implement has() method
This commit is contained in:
parent
18acad19b9
commit
11314fb8d1
3 changed files with 19 additions and 0 deletions
|
@ -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') {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue