use redis expire event to delete stored data immediately

This commit is contained in:
Edmund Huggett 2017-11-15 12:31:22 +00:00
parent 490a1e88eb
commit 58840e2c00
No known key found for this signature in database
GPG Key ID: C403E0007DCEEEB0
2 changed files with 19 additions and 0 deletions

View File

@ -14,6 +14,11 @@ const conf = convict({
default: 'localhost', default: 'localhost',
env: 'REDIS_HOST' env: 'REDIS_HOST'
}, },
redis_event_expire: {
format: Boolean,
default: false,
env: 'REDIS_EVENT_EXPIRE'
},
listen_port: { listen_port: {
format: 'port', format: 'port',
default: 1443, default: 1443,

View File

@ -61,6 +61,20 @@ if (config.s3_bucket) {
}; };
} }
if (config.redis_event_expire) {
const forceDelete = config.s3_bucket ? awsForceDelete : localForceDelete;
const redis_sub = redis_client.duplicate();
const subKey = '__keyevent@0__:expired';
redis_sub.psubscribe(subKey, function() {
log.info('Redis:', 'subscribed to expired key events');
});
redis_sub.on('pmessage', function(channel, message, id) {
log.info('RedisExpired:', id);
forceDelete(id);
});
}
function flushall() { function flushall() {
redis_client.flushdb(); redis_client.flushdb();
} }