blacklist with automatic garbage collector
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@ -11,14 +11,18 @@ import { Redis } from '../Redis';
|
||||
const logger = debug ('RedisBlacklistStore');
|
||||
|
||||
export class RedisBlacklistStore extends Redis {
|
||||
public async add (key: string): Promise<void> {
|
||||
public async add (key: string, valid_until: Date): Promise<void> {
|
||||
const log = logger.extend ('set');
|
||||
log ('trying to add key %s to redis blacklist', key);
|
||||
if (!this.is_active) {
|
||||
log ('redis is inactive, skipping');
|
||||
return;
|
||||
}
|
||||
await this.redis.sadd ('blacklist', key);
|
||||
await this.redis.setex (
|
||||
`blacklist_${key}`,
|
||||
(valid_until.getTime () - Date.now ()) / 1000,
|
||||
1
|
||||
);
|
||||
log ('saved key');
|
||||
}
|
||||
|
||||
@ -29,7 +33,7 @@ export class RedisBlacklistStore extends Redis {
|
||||
log ('redis is inactive, skipping');
|
||||
return;
|
||||
}
|
||||
await this.redis.srem ('blacklist', key);
|
||||
await this.redis.del (`blacklist_${key}`);
|
||||
log ('removed key');
|
||||
}
|
||||
|
||||
@ -40,7 +44,7 @@ export class RedisBlacklistStore extends Redis {
|
||||
log ('redis is inactive, skipping');
|
||||
return false;
|
||||
}
|
||||
const res = await this.redis.sismember ('blacklist', key) === 1;
|
||||
const res = await this.redis.exists (`blacklist_${key}`) === 1;
|
||||
log ('found key %s', res);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user