MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / rememberSlaveKeyWithExpire

Function rememberSlaveKeyWithExpire

src/expire.cpp:667–695  ·  view source on GitHub ↗

Track keys that received an EXPIRE or similar command in the context * of a writable replica. */

Source from the content-addressed store, hash-verified

665/* Track keys that received an EXPIRE or similar command in the context
666 * of a writable replica. */
667void rememberSlaveKeyWithExpire(redisDb *db, robj *key) {
668 if (slaveKeysWithExpire == NULL) {
669 static dictType dt = {
670 dictSdsHash, /* hash function */
671 NULL, /* key dup */
672 NULL, /* val dup */
673 dictSdsKeyCompare, /* key compare */
674 dictSdsDestructor, /* key destructor */
675 NULL, /* val destructor */
676 NULL /* allow to expand */
677 };
678 slaveKeysWithExpire = dictCreate(&dt,NULL);
679 }
680 if (db->id > 63) return;
681
682 dictEntry *de = dictAddOrFind(slaveKeysWithExpire,ptrFromObj(key));
683 /* If the entry was just created, set it to a copy of the SDS string
684 * representing the key: we don't want to need to take those keys
685 * in sync with the main DB. The keys will be removed by expireSlaveKeys()
686 * as it scans to find keys to remove. */
687 if (de->key == ptrFromObj(key)) {
688 de->key = sdsdup(szFromObj(key));
689 dictSetUnsignedIntegerVal(de,0);
690 }
691
692 uint64_t dbids = dictGetUnsignedIntegerVal(de);
693 dbids |= (uint64_t)1 << db->id;
694 dictSetUnsignedIntegerVal(de,dbids);
695}
696
697/* Return the number of keys we are tracking. */
698size_t getSlaveKeyWithExpireCount(void) {

Callers 1

setExpireFunction · 0.85

Calls 5

dictAddOrFindFunction · 0.85
ptrFromObjFunction · 0.85
sdsdupFunction · 0.85
szFromObjFunction · 0.85
dictCreateFunction · 0.70

Tested by

no test coverage detected