Merge pull request #536 from ehuggett/on-redis-expire

use redis expire event to delete stored data immediately
This commit is contained in:
Danny Coates 2018-01-31 13:23:33 -08:00 committed by GitHub
commit 10e80edb1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

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

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() {
redis_client.flushdb();
}