From b7514941f0c4a2e9176cdd5e0130749d6e8c8104 Mon Sep 17 00:00:00 2001 From: Timo Hocker <35867059+TimoHocker@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:56:02 +0200 Subject: [PATCH] Revert "refactoring redis for multiple value classes" This reverts commit d5c136790ee7521dc5d884e23b108a22c122c49d. --- lib/Redis.ts | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/Redis.ts b/lib/Redis.ts index 648b850..d36cc2e 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -11,9 +11,6 @@ import { LabelledKey } from './Key'; const logger = debug ('redis'); -export type SyncClass = 'blacklist' | 'keystore' -export type SyncValue = LabelledKey | string; - export class Redis { private _redis: IORedis | null = null; @@ -55,31 +52,20 @@ export class Redis { log ('done'); } - public async set ( - sync_class: SyncClass, - key: string, - value: SyncValue - ): Promise { - const log = logger.extend ('set'); - log ('trying to set %s value %s to redis', sync_class, key); + public async set_key (key: LabelledKey): Promise { + const log = logger.extend ('set_key'); + log ('trying to set key %s to redis', key.index); if (this._redis === null) { log ('redis is inactive, skipping'); return; } - let valid_for = null; - if (sync_class === 'keystore') { - valid_for = Math.floor ( - (key.valid_until - (new Date) - .getTime ()) / 1000 - ); - log ('key is valid for %d seconds', valid_for); - } - if (valid_for === null) - await this._redis.set (key, JSON.stringify (value)); - else - await this._redis.setex (key, valid_for, JSON.stringify (value)); - - log ('saved value'); + const valid_for = Math.floor ( + (key.valid_until - (new Date) + .getTime ()) / 1000 + ); + log ('key is valid for %d seconds', valid_for); + await this._redis.setex (key.index, valid_for, JSON.stringify (key)); + log ('saved key'); } public async get_key (index: string): Promise {