MCPcopy Create free account
hub / github.com/F-Stack/f-stack / watchForKey

Function watchForKey

app/redis-6.2.6/src/multi.c:297–324  ·  view source on GitHub ↗

Watch for the specified key */

Source from the content-addressed store, hash-verified

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