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

Function watchForKey

src/multi.cpp:303–330  ·  view source on GitHub ↗

Watch for the specified key */

Source from the content-addressed store, hash-verified

301
302/* Watch for the specified key */
303void watchForKey(client *c, robj *key) {
304 list *clients = NULL;
305 listIter li;
306 listNode *ln;
307 watchedKey *wk;
308
309 /* Check if we are already watching for this key */
310 listRewind(c->watched_keys,&li);
311 while((ln = listNext(&li))) {
312 wk = (watchedKey*)listNodeValue(ln);
313 if (wk->db == c->db && equalStringObjects(key,wk->key))
314 return; /* Key already watched */
315 }
316 /* This key is not already watched in this DB. Let's add it */
317 clients = (decltype(clients)) dictFetchValue(c->db->watched_keys,key);
318 if (!clients) {
319 clients = listCreate();
320 dictAdd(c->db->watched_keys,key,clients);
321 incrRefCount(key);
322 }
323 listAddNodeTail(clients,c);
324 /* Add the new key to the list of keys watched by this client */
325 wk = (watchedKey*)zmalloc(sizeof(*wk), MALLOC_SHARED);
326 wk->key = key;
327 wk->db = c->db;
328 incrRefCount(key);
329 listAddNodeTail(c->watched_keys,wk);
330}
331
332/* Unwatch all the keys watched by this client. To clean the EXEC dirty
333 * flag is up to the caller. */

Callers 1

watchCommandFunction · 0.85

Calls 9

listRewindFunction · 0.85
listNextFunction · 0.85
equalStringObjectsFunction · 0.85
dictFetchValueFunction · 0.85
listCreateFunction · 0.85
incrRefCountFunction · 0.85
listAddNodeTailFunction · 0.85
zmallocFunction · 0.85
dictAddFunction · 0.70

Tested by

no test coverage detected