Skip to content

Commit

Permalink
use redis expire event to delete stored data immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuggett committed Nov 15, 2017
1 parent 490a1e8 commit 58840e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const conf = convict({
default: 'localhost',
env: 'REDIS_HOST'
},
redis_event_expire: {
format: Boolean,
default: false,
env: 'REDIS_EVENT_EXPIRE'
},
listen_port: {
format: 'port',
default: 1443,
Expand Down
14 changes: 14 additions & 0 deletions server/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 58840e2

Please sign in to comment.