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

Function replicationScriptCacheAdd

src/replication.cpp:4572–4591  ·  view source on GitHub ↗

Add an entry into the script cache, if we reach max number of entries the * oldest is removed from the list. */

Source from the content-addressed store, hash-verified

4570/* Add an entry into the script cache, if we reach max number of entries the
4571 * oldest is removed from the list. */
4572void replicationScriptCacheAdd(sds sha1) {
4573 int retval;
4574 sds key = sdsdup(sha1);
4575
4576 /* Evict oldest. */
4577 if (listLength(g_pserver->repl_scriptcache_fifo) == g_pserver->repl_scriptcache_size)
4578 {
4579 listNode *ln = listLast(g_pserver->repl_scriptcache_fifo);
4580 sds oldest = (sds)listNodeValue(ln);
4581
4582 retval = dictDelete(g_pserver->repl_scriptcache_dict,oldest);
4583 serverAssert(retval == DICT_OK);
4584 listDelNode(g_pserver->repl_scriptcache_fifo,ln);
4585 }
4586
4587 /* Add current. */
4588 retval = dictAdd(g_pserver->repl_scriptcache_dict,key,NULL);
4589 listAddNodeHead(g_pserver->repl_scriptcache_fifo,key);
4590 serverAssert(retval == DICT_OK);
4591}
4592
4593/* Returns non-zero if the specified entry exists inside the cache, that is,
4594 * if all the slaves are aware of this script SHA1. */

Callers 1

evalGenericCommandFunction · 0.85

Calls 5

sdsdupFunction · 0.85
listDelNodeFunction · 0.85
listAddNodeHeadFunction · 0.85
dictDeleteFunction · 0.70
dictAddFunction · 0.70

Tested by

no test coverage detected