Revert "refactoring redis for multiple value classes"
This reverts commit d5c136790ee7521dc5d884e23b108a22c122c49d.
This commit is contained in:
parent
d5c136790e
commit
b7514941f0
26
lib/Redis.ts
26
lib/Redis.ts
@ -11,9 +11,6 @@ import { LabelledKey } from './Key';
|
|||||||
|
|
||||||
const logger = debug ('redis');
|
const logger = debug ('redis');
|
||||||
|
|
||||||
export type SyncClass = 'blacklist' | 'keystore'
|
|
||||||
export type SyncValue = LabelledKey | string;
|
|
||||||
|
|
||||||
export class Redis {
|
export class Redis {
|
||||||
private _redis: IORedis | null = null;
|
private _redis: IORedis | null = null;
|
||||||
|
|
||||||
@ -55,31 +52,20 @@ export class Redis {
|
|||||||
log ('done');
|
log ('done');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async set (
|
public async set_key (key: LabelledKey): Promise<void> {
|
||||||
sync_class: SyncClass,
|
const log = logger.extend ('set_key');
|
||||||
key: string,
|
log ('trying to set key %s to redis', key.index);
|
||||||
value: SyncValue
|
|
||||||
): Promise<void> {
|
|
||||||
const log = logger.extend ('set');
|
|
||||||
log ('trying to set %s value %s to redis', sync_class, key);
|
|
||||||
if (this._redis === null) {
|
if (this._redis === null) {
|
||||||
log ('redis is inactive, skipping');
|
log ('redis is inactive, skipping');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let valid_for = null;
|
const valid_for = Math.floor (
|
||||||
if (sync_class === 'keystore') {
|
|
||||||
valid_for = Math.floor (
|
|
||||||
(key.valid_until - (new Date)
|
(key.valid_until - (new Date)
|
||||||
.getTime ()) / 1000
|
.getTime ()) / 1000
|
||||||
);
|
);
|
||||||
log ('key is valid for %d seconds', valid_for);
|
log ('key is valid for %d seconds', valid_for);
|
||||||
}
|
await this._redis.setex (key.index, valid_for, JSON.stringify (key));
|
||||||
if (valid_for === null)
|
log ('saved key');
|
||||||
await this._redis.set (key, JSON.stringify (value));
|
|
||||||
else
|
|
||||||
await this._redis.setex (key, valid_for, JSON.stringify (value));
|
|
||||||
|
|
||||||
log ('saved value');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get_key (index: string): Promise<LabelledKey | null> {
|
public async get_key (index: string): Promise<LabelledKey | null> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user