Skip to content

best way to save what you love

api/store: use basic strings instead of hashes for keys

jj693204b799d9
diff --git a/api/src/store/redis-store.js b/api/src/store/redis-store.js
index dc4e405e..0b359526 100644
--- a/api/src/store/redis-store.js
+++ b/api/src/store/redis-store.js
@@ -26,43 +26,39 @@ export default class RedisStore extends Store {
async _get(key) {
await this.#connected;
- const data = await this.#client.hGetAll(
+ const valueType = await this.#client.get(this.#keyOf(key) + '_t');
+ const value = await this.#client.get(
commandOptions({ returnBuffers: true }),
this.#keyOf(key)
);
- if (!data.d) {
+ if (!value) {
return null;
}
- const type = data.t;
- if (type && type[0] === 'b'.charCodeAt())
- return data.d;
+ if (valueType === 'b')
+ return value;
else
- return JSON.parse(data.d);
+ return JSON.parse(value);
}
async _set(key, val, exp_sec = -1) {
await this.#connected;
- const out = { d: val };
+ const options = exp_sec > 0 ? { EX: exp_sec } : undefined;
+
if (val instanceof Buffer) {
- out.t = 'b';
- } else {
- out.d = JSON.stringify(val);
+ await this.#client.set(
+ this.#keyOf(key) + '_t',
+ 'b',
+ options
+ );
}
- await this.#client.hSet(
+ await this.#client.set(
this.#keyOf(key),
- out
+ val,
+ options
);
-
- if (exp_sec > 0) {
- await this.#client.hExpire(
- this.#keyOf(key),
- Object.keys(out),
- exp_sec
- );
- }
}
}