Skip to content

best way to save what you love

api/store: implement has() method

jj11314fb8d15e
diff --git a/api/src/store/base-store.js b/api/src/store/base-store.js
index 3f81d8d9..9938c852 100644
--- a/api/src/store/base-store.js
+++ b/api/src/store/base-store.js
@@ -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') {
diff --git a/api/src/store/memory-store.js b/api/src/store/memory-store.js
index 07e94ec2..b30908d5 100644
--- a/api/src/store/memory-store.js
+++ b/api/src/store/memory-store.js
@@ -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);
diff --git a/api/src/store/redis-store.js b/api/src/store/redis-store.js
index cce158e0..dc4e405e 100644
--- a/api/src/store/redis-store.js
+++ b/api/src/store/redis-store.js
@@ -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;