-
-
Save dspezia/3258233 to your computer and use it in GitHub Desktop.
Redis hack to get notified when a key expire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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