Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions libs/redis-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,6 @@ export class RedisStore<T> implements IStore<T> {
return this.decode(data);
}

/**
* Retrieves multiple keys from Redis using a single hmget call.
* @param keys The keys to retrieve
* @returns An array of the values
*/
public async getM(...keys: string[]) {
const data = await this.redis.hmget(this.hash, ...keys);
return data.map(e => e ? this.decode(e) : null);
}

public async set(key: string, value: T) {
const size = await this.redis.hlen(this.hash);
if (this.maxSize && size >= this.maxSize) await this.empty();
Expand All @@ -162,10 +152,6 @@ export class RedisStore<T> implements IStore<T> {
return count > 0;
}

public deleteM(...keys: string[]) {
return this.redis.hdel(this.hash, ...keys);
}

public async findKey(cb: StoreSingleEntryCallback<T>) {
for await (const [key, value] of this) {
if (cb(value, key)) return key;
Expand Down Expand Up @@ -220,13 +206,10 @@ export class RedisStore<T> implements IStore<T> {
}

public async map<V = T>(cb: StoreMapCallback<V, T>) {
const raw = await this.redis.hgetall(this.hash);
return Object
.entries(raw)
.map(([key, value]) => cb(
this.decode(value),
key
));
const output: V[] = [];
for await (const [key, value] of this) output.push(cb(value, key));

return output;
}

public async empty(cb?: StoreSingleEntryCallback<T>) {
Expand Down