Skip to content

Instantly share code, notes, and snippets.

@dspezia dspezia/db.c
Created Aug 4, 2012

Embed
What would you like to do?
Redis hack to get notified when a key expire
// Change propagateExpire function in db.c as follows:
void propagateExpire(redisDb *db, robj *key) {
/* HORRIBLE HACK STARTS HERE */
/* robj *argv[2]; */
robj *argv[3];
/* HORRIBLE HACK ENDS HERE */
argv[0] = shared.del;
argv[1] = key;
incrRefCount(argv[0]);
incrRefCount(argv[1]);
if (server.aof_state != REDIS_AOF_OFF)
feedAppendOnlyFile(server.delCommand,db->id,argv,2);
if (listLength(server.slaves))
replicationFeedSlaves(server.slaves,db->id,argv,2);
decrRefCount(argv[0]);
decrRefCount(argv[1]);
/* HORRIBLE HACK STARTS HERE */
if ( ((char *)(key->ptr))[0] == '@' )
{
static redisClient *c = NULL;
if ( !c )
c = createClient(-1);
argv[0] = createStringObject("LPUSH",5);
argv[1] = createStringObject("#expired",8);
argv[2] = key;
incrRefCount(argv[2]);
c->argv = argv;
c->argc = 3;
c->cmd = lookupCommand(argv[0]->ptr);
selectDb(c,db->id);
call(c,REDIS_CALL_SLOWLOG | REDIS_CALL_STATS);
c->bufpos = 0;
while(listLength(c->reply))
listDelNode(c->reply,listFirst(c->reply));
decrRefCount(argv[0]);
decrRefCount(argv[1]);
decrRefCount(argv[2]);
}
/* HORRIBLE HACK ENDS HERE */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.